I have a custom CursorAdapter which sets a handler for OnCheckedChangeListener inside bindView (the layout in newView implements the Checkable interface). '=>' is the anonymous function syntax in scala:
def setTaskCheckboxToggleListener() = {
val v = view.findViewById(R.id.taskCheckbox).asInstanceOf[CheckBox]
v.setOnCheckedChangeListener(
(buttonView: CompoundButton, isChecked: Boolean) => {
handler(buttonView, isChecked)
}
)
}
The adapter is used with a listView. Now the handler is set once in the activity containing the listView using:
listView.setAdapter(Tasks.adapter(context))
listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
listView.getAdapter().registerCheckBoxStateChangeHandler((buttonView: CompoundButton, _) => {
findViewById(R.id.commandButton).astInstanceOf[Button].setText("✓")
}
This handler for some reason prevents the checkbox from being toggled. In comparison, the checkbox just works with an empty handler or a handler that doesn't call .setText on the UI element. What could be the problem here?
Checkable layout used in the Adapter, the xml file in res/ has a CheckBox element:
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.{CheckBox, Checkable, CheckedTextView, RelativeLayout}
class TaskLayout(context: Context, attrs: AttributeSet)
extends RelativeLayout(context, attrs) with Checkable {
private var checkbox: CheckBox = _
override def onFinishInflate(): Unit = {
super.onFinishInflate();
for (i <- 0 to getChildCount()) {
val v = getChildAt(i)
if (v.isInstanceOf[CheckBox])
checkbox = v.asInstanceOf[CheckBox];
}
}
override def isChecked(): Boolean = {
if (checkbox != null)
checkbox.isChecked()
else
false
}
override def setChecked(checked: Boolean) =
if (checkbox != null) checkbox.setChecked(checked)
override def toggle() =
if (checkbox != null) checkbox.toggle();
}
Commenting out listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE) solved the problem.
Related
After swiping an item in RecyclerView I want it to go back without swiping it back manually.
Here is an swipeable item in RecyclerView.
Item in RecyclerView
Swiping...
After swipe event I want this item to go back, as if it was swiped not far enough, but event must happen. How can I do this?
After swipe
Here is my SwipeHelper, which keeps background static:
abstract class ProfileSwipeHelper : ItemTouchHelper.SimpleCallback(0,
ItemTouchHelper.LEFT
) {
override fun onMove(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder
): Boolean {
return true
}
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
if (viewHolder != null) {
ItemTouchHelper.Callback.getDefaultUIUtil().onSelected((viewHolder as ProfilesAdapter.ViewHolder).foreground)
}
}
override fun onChildDraw(
c: Canvas,
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
dX: Float,
dY: Float,
actionState: Int,
isCurrentlyActive: Boolean
) {
getDefaultUIUtil().onDraw(c, recyclerView,
(viewHolder as ProfilesAdapter.ViewHolder).foreground, dX, dY,
actionState, isCurrentlyActive)
}
override fun onChildDrawOver(
c: Canvas,
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder?,
dX: Float,
dY: Float,
actionState: Int,
isCurrentlyActive: Boolean
) {
getDefaultUIUtil().onDrawOver(
c, recyclerView,
(viewHolder as ProfilesAdapter.ViewHolder).foreground, dX, dY,
actionState, isCurrentlyActive)
}
override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
getDefaultUIUtil().clearView((viewHolder as ProfilesAdapter.ViewHolder).foreground)
}
}
And here onSwiped event in main activity, only with Toast:
//Main Activity
val context : Context = this
val deleteSwipeHandler1 = object : ProfileSwipeHelper() {
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
Toast.makeText(context, "swiped", Toast.LENGTH_SHORT).show()
}
}
ItemTouchHelper(deleteSwipeHandler1).attachToRecyclerView(rv_profiles)
You can use Multiswipe library. Read complete explanations here. If you want to use Java read this. Below is
a concise explanation without using complete options of this library:
add jitpack and Multiswipe library to your project:
in settings.gradle or root build.gradle:
repositories {
//...
maven { url 'https://jitpack.io' }
}
in app's build.gradle:
dependencies {
implementation 'com.github.ygngy:multiswipe:1.2.1'
}
implement MultiSwipe in ViewHolder:
import androidx.recyclerview.widget.RecyclerView
import android.view.View
import com.github.ygngy.multiswipe.MultiSwipe
import com.github.ygngy.multiswipe.LeftSwipeList
import com.github.ygngy.multiswipe.RightSwipeList
class ViewHolder(private val view: View) : RecyclerView.ViewHolder(view), MultiSwipe {
var mLeftSwipeList: LeftSwipeList? = null
var mRightSwipeList: RightSwipeList? = null
// todo other ViewHolder codes...
fun bind() {
// Each swipe contains of at least an id and an icon
val likeSwipe = Swipe(
context = context, // context used to extract default colors and margins from resources
id = SWIPE_TO_LIKE_ID, // swipe id will be sent to onSwipeDone when swipe is completed
activeIcon = getDrawable(R.drawable.ic_like_24)!!, // swipe icon
activeLabel = getString(R.string.like), // OPTIONAL swipe label
acceptIcon = getDrawable(R.drawable.ic_like_accept_24)!!,// OPTIONAL icon used when swipe displacement is greater than "accept boundary"
acceptLabel = getString(R.string.like_accept),// OPTIONAL label used when swipe swipe displacement is greater than "accept boundary"
inactiveIcon = getDrawable(R.drawable.ic_disabled_like_24)!!// OPTIONAL icon used when this swipe could be next swipe
)
// Create other swipes (shareSwipe, copySwipe, ...) in a similar way.
// If row has left swipes, create left swipe list in the desired order like below:
mLeftSwipeList = LeftSwipeList (shareSwipe, copySwipe, cutSwipe)
// If row has right swipes, create right swipe list in the desired order like below:
mRightSwipeList = RightSwipeList (likeSwipe, editSwipe, delSwipe)
}
// Don't recreate swipes or any object here
override val leftSwipeList: LeftSwipeList?
get() = mLeftSwipeList
// Don't recreate swipes or any object here
override val rightSwipeList: RightSwipeList?
get() = mRightSwipeList
// Here handle swipe event and/or return some data to MultiSwipeListener
override fun onSwipeDone(swipeId: Int): Any? {
// Instead you may choose to only return data
// from this method to consume event at Activity or Fragment
when(swipeId) {
SWIPE_TO_SHARE_ID -> {
// todo share
}
SWIPE_TO_COPY_ID -> {
// todo copy
}
//...
}
return MyData()// return any data to Activity or Fragment
}
}
attach library to recyclerview at activity or fragment:
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.github.ygngy.multiswipe.MultiSwipeListener
import com.github.ygngy.multiswipe.SwipeDirection
import com.github.ygngy.multiswipe.multiSwiping // importing extension function
class DemoActivity : AppCompatActivity() {
// todo other activity codes...
override fun onCreate(savedInstanceState: Bundle?) {
// todo other onCreate codes...
// attaching Multiswipe to RecycerView
recyclerView.multiSwiping(
swipeThreshold = 0.5f, // OPTIONAL, the fraction of view for complete swipe threshold
object: MultiSwipeListener { // OPTIONAL listener
// This method is called after onSwipeDone of ViewHolder
// and data is the returned value of onSwipeDone of ViewHolder
override fun onSwipeDone(swipeId: Int, data: Any?) {
// data is the return value of "ViewHolder.onSwipeDone"
// cast to data you returned from "ViewHolder.onSwipeDone"
val myData = data as MyData?
when(swipeId) {
SWIPE_TO_SHARE_ID -> shareItem(myData)
SWIPE_TO_COPY_ID -> copyItem(myData)
//...
}
}
/***
This method will be called when direction changes in each swipe.
This method could be used to hide on screen widgets such as FABs.
direction may be:
- START (when user opens start side of view),
- END (when user opens end side of view),
- NONE (when swipe is closing without user interaction)
***/
override fun swiping(direction: SwipeDirection, swipeListSize: Int) {
// here i hide FAB when user is swiping end side actively
if (direction == SwipeDirection.END) fab.hide() else fab.show()
}
})
}
}
Hello fellow programmers!
I am currently facing problem with RecyclerView's add animation with smooth scroll simulataneously.
Problem
I have implemented RecyclerView with ListAdapter and DiffUtil for cool animations (insert, remove). The problem is that I can't get it to smooth scroll to added position without cancelling insert animation.
User is supposed to type in 'exercise name' and then push 'add' button to add it to current 'exercise list'. Then this exercise should be added to RecyclerView list. Everything works fine here, but I can't achieve smooth scroll to new item position without cancelling (or accelerating) insert animation.
viewModel.exerciseListLiveData.observe(viewLifecycleOwner, {
adapter.submitList(it) {
// Cancels insert animation (or accelerates it rapidly) - bad UX...
layoutManager.smoothScrollToPosition(recyclerView, RecyclerView.State(), 0)
}
})
On the other hand, substituting smoothScrollToPosition with scrollToPosition works fine but when there's more items (recycler's view is filled from top to bottom) it blinks on scroll. I know it's rather jump than smooth scroll but then, why is it working with add animation so it doesn't cancel or accelerate?
viewModel.exerciseListLiveData.observe(viewLifecycleOwner, {
adapter.submitList(it) {
// Works fine (recyclerView is scrolling to added position)
// but when there's no room to display more items - it scrolls to it with blink...
// which I simply can't stand!
layoutManager.smoothScrollToPosition(recyclerView, RecyclerView.State(), 0)
}
})
Possible solution?
I'm supposed to first smoothScrollToPosition(0) to top-most position, then call submitList(it) and finally call scrollToPosition(0) but I can't achieve that (it is doing so fast, simultaneously, that it's layering each other). Maybe I should use coroutines? Don't know...
How am I supposed to add proper delay? Maybe I am doing something wrong because i read that some programmers had this autoscroll when added item.
Code sample
Adapter
class ExercisesListAdapter :
ListAdapter<Exercise, ExercisesListAdapter.ExerciseItemViewHolder>(ExercisesListDiffUtil()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExerciseItemViewHolder {
val inflater = LayoutInflater.from(parent.context)
val binding: ItemRecyclerviewExerciseBinding =
DataBindingUtil.inflate(inflater, R.layout.item_recyclerview_exercise, parent, false)
return ExerciseItemViewHolder(binding)
}
override fun onBindViewHolder(holder: ExerciseItemViewHolder, position: Int) {
val currentExercise = getItem(position)
holder.bind(currentExercise)
}
override fun getItemId(position: Int): Long {
return getItem(position).id
}
// Item ViewHolder class
class ExerciseItemViewHolder(private val binding: ItemRecyclerviewExerciseBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(itemExercise: Exercise) {
binding.textCardExerciseName.text = itemExercise.name
}
}
}
DiffUtil
class ExercisesListDiffUtil: DiffUtil.ItemCallback<Exercise>() {
override fun areItemsTheSame(oldItem: Exercise, newItem: Exercise): Boolean {
return oldItem.id == newItem.id
}
override fun areContentsTheSame(oldItem: Exercise, newItem: Exercise): Boolean {
return oldItem == newItem
}
}
ViewModel
class CreateWorkoutViewModel(private val repository: WorkoutRepository) : ViewModel() {
private var exerciseId = 0L
private var exerciseList = mutableListOf<Exercise>()
val exerciseName = MutableLiveData<String?>()
private val _exerciseListLiveData = MutableLiveData<List<Exercise>>()
val exerciseListLiveData: LiveData<List<Exercise>>
get() = _exerciseListLiveData
fun onAddExercise() {
if (canValidateExerciseName())
addExerciseToList()
}
fun onAddWorkout() {
exerciseList.removeAt(2)
_exerciseListLiveData.value = exerciseList.toList()
}
private fun canValidateExerciseName(): Boolean {
return !exerciseName.value.isNullOrBlank()
}
private fun addExerciseToList() {
exerciseList.add(0, Exercise(exerciseId++, exerciseName.value!!))
_exerciseListLiveData.value = exerciseList.toList()
}
}
Fragment
class CreateWorkoutFragment : Fragment() {
lateinit var binding: FragmentCreateWorkoutBinding
lateinit var viewModel: CreateWorkoutViewModel
lateinit var recyclerView: RecyclerView
lateinit var adapter: ExercisesListAdapter
lateinit var layoutManager: LinearLayoutManager
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding =
DataBindingUtil.inflate(inflater, R.layout.fragment_create_workout, container, false)
setViewModel()
setRecyclerView()
// Observers:
// Update RecyclerView list on change
viewModel.exerciseListLiveData.observe(viewLifecycleOwner, {
adapter.submitList(it) {
layoutManager.smoothScrollToPosition(recyclerView, RecyclerView.State(), 0)
}
})
return binding.root
}
private fun setRecyclerView() {
recyclerView = binding.recyclerviewExercises
setLayoutManager()
setAdapter()
}
private fun setLayoutManager() {
layoutManager = LinearLayoutManager(context)
recyclerView.layoutManager = layoutManager
}
private fun setAdapter() {
adapter = ExercisesListAdapter()
adapter.setHasStableIds(true)
recyclerView.adapter = adapter
}
private fun setViewModel() {
val dao = WorkoutDatabase.getInstance(requireContext()).workoutDAO
val repository = WorkoutRepository(dao)
val factory = CreateWorkoutViewModelFactory(repository)
viewModel = ViewModelProvider(this, factory).get(CreateWorkoutViewModel::class.java)
binding.viewModel = viewModel
binding.lifecycleOwner = this
}
}
EDIT
I got it working but it's not 'elegant' way and insert animation is canceled through process :/
adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
if(layoutManager.findFirstCompletelyVisibleItemPosition() == 0)
layoutManager.scrollToPosition(0)
else {
recyclerView.clearAnimation()
layoutManager.smoothScrollToPosition(recyclerView, RecyclerView.State(), 0)
}
}
})
I am new to Firebase and RecyclerViews and I am trying to get a list of ingredients from my Firebase Database and I want to create checkboxes for every item I retrieve from the database. I got as far as creating a RecyclerView and adapter for my Firebase Query but binding lists from the query doesn't seem to be covered anywhere I could find.
Please find below the code for putting the data into the recycler view as well as the layout files being used for the recycler view.
Data being retrieved
that I want to display the original field of my object as checkboxes
ShoppingListFragment.kt
class ShoppingListFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
//Enable Firestore logging
FirebaseFirestore.setLoggingEnabled(true)
//Firestore
firestore = Firebase.firestore
// Get recipes that the user has liked up to ${LIMIT}
query = firestore.collection("recipes").whereArrayContains(
"plannedBy",
Firebase.auth.uid.toString()
)
.orderBy("name", Query.Direction.ASCENDING)
.limit(LIMIT.toLong())
// Init the adapter to hold the recipe objects.
adapter = object : ShoppingListAdapter(query) {
override fun onDataChanged() {
if (itemCount == 0) {
shoppingListRecycler.visibility = View.GONE
viewEmpty.visibility = View.VISIBLE
} else {
shoppingListRecycler.visibility = View.VISIBLE
viewEmpty.visibility = View.GONE
}
}
override fun onError(e: FirebaseFirestoreException) {
// Show a snackbar on errors
view?.let {
Snackbar.make(
it,
"Error: check logs for info.", Snackbar.LENGTH_LONG
).show()
}
}
}
...
}
...
}
ShoppingListAdapter.kt
open class ShoppingListAdapter(query: Query) :
FirestoreAdapter<ShoppingListViewHolder>(query) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ShoppingListViewHolder {
return ShoppingListViewHolder(
ItemShoppingListBinding.inflate(
LayoutInflater.from(parent.context), parent, false))
}
override fun onBindViewHolder(holder: ShoppingListViewHolder, position: Int) {
holder.bind(getSnapshot(position))
}
}
ShoppingListViewHolder.kt
class ShoppingListViewHolder(val binding: ItemShoppingListBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(snapshot: DocumentSnapshot) {
val recipe = snapshot.toObject<Recipe>() ?: return
binding.listTitle.text = recipe.name
if(recipe.ingredients.size > 1) {
binding.shoppingListItem.text = recipe.ingredients[0].original
for(i in 1 until recipe.ingredients.size) {
val checkBox = CheckBox() //Not sure what to put here as the context for my recyclerview List Item
checkBox.text = recipe.ingredients[i].original
checkBox.layoutParams = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
binding.shoppingListContainer.addView(checkBox)
}
} else {
binding.shoppingListItem.text = recipe.ingredients[0].original
}
}
}
I have tried passing a context parameter through ShoppingListViewHolder.kt and in turn adding that parameter to the adapter and so forth like so.
class ShoppingListViewHolder(val binding: ItemShoppingListBinding, val context: Context) : RecyclerView.ViewHolder(binding.root) {
fun bind(snapshot: DocumentSnapshot) {
val recipe = snapshot.toObject<Recipe>() ?: return
binding.listTitle.text = recipe.name
if(recipe.ingredients.size > 1) {
binding.shoppingListItem.text = recipe.ingredients[0].original
for(i in 1 until recipe.ingredients.size) {
val checkBox = CheckBox(context)
...
}
ShoppingListFragment.kt
// Init the adapter to hold the recipe objects.
adapter = object : ShoppingListAdapter(query, requireContext()) {
override fun onDataChanged() {
if (itemCount == 0) {
shoppingListRecycler.visibility = View.GONE
viewEmpty.visibility = View.VISIBLE
} else {
shoppingListRecycler.visibility = View.VISIBLE
viewEmpty.visibility = View.GONE
}
}
override fun onError(e: FirebaseFirestoreException) {
// Show a snackbar on errors
view?.let {
Snackbar.make(
it,
"Error: check logs for info.", Snackbar.LENGTH_LONG
).show()
}
}
}
But all that did was create a huge amount of white space between entries. After some debugging, it looks like passing the context from the fragment gave it the MainActivity context. I'm not too sure where to go from here and any help would be appreciated. Thank you!
you can use binding.root.context except passing context
I created a WaterQualityChecksDialogFragment, please correct if I have not written it correctly.
WaterQualityChecksDialogFragment.kt
class WaterQualityChecksDialogFragment : DialogFragment() {
#Inject
private lateinit var app: App
fun newTargetInstance(): WaterQualityChecksDialogFragment {
val fragment = WaterQualityChecksDialogFragment()
return fragment
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
app!!.bus.post(ScreenDimEvent(false))
val builder = AlertDialog.Builder(activity!!.applicationContext)
// Get the layout inflater
val inflater = activity!!.layoutInflater
#SuppressLint("InflateParams")
val inflatedView = inflater.inflate(R.layout.dialog_water_quality_cheks, null)
builder
.setView(inflatedView)
.setCancelable(false)
/*
* setPositiveButton and setNeutralButton are also set (and overridden) in {#link #onStart}
* to stop Android automatically closing the dialog on click
*/
.setPositiveButton(R.string.fuel_order_signature_dialog_save) { dialog, id ->
}
.setNeutralButton(R.string.fuel_order_signature_dialog_clear) { dialog, id ->
}
val dialog = builder.create()
// Stop touch events outside the dialog from cancelling/dismissing
dialog.setCanceledOnTouchOutside(false)
return dialog
}
interface WaterQCChecksDialogListener {
fun onDialogPositiveClick(dialog: WaterQualityChecksDialogFragment)
fun onDialogNegativeClick(dialog: WaterQualityChecksDialogFragment)
}
}
ServiceOrderDialogHelper.java
public void showWaterQCChecksDioalog(){
//Cannot call newTargetInstance() method.
waterQualityChecksDialogFragment = WaterQualityChecksDialogFragment.newTargetInstance()
}
Put newTargetInstance() inside companion object to make this static like java
companion object {
fun newTargetInstance(): WaterQualityChecksDialogFragment {
val fragment = WaterQualityChecksDialogFragment()
return fragment
}
}
And call from java like below:
WaterQualityChecksDialogFragment.Companion.newTargetInstance();
Please check this code, it may helps you
class DialogClassSample : DialogFragment() {
companion object {
fun newInstance(): DialogClassSample {
val dialog = DialogClassSample()
return dialog
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
isCancelable = false
return inflater.inflate(R.layout.view, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setListener()
}
fun setListener() {
button.setOnClickListener({
dismiss()
})
}
override fun onResume() {
super.onResume()
val window = dialog?.window
val size = Point()
val display = window?.windowManager?.defaultDisplay
display?.getSize(size)
val width = size.x
window?.setLayout((width * 0.85).toInt(), WindowManager.LayoutParams.WRAP_CONTENT)
window?.setGravity(Gravity.CENTER)
}
}
and call fron your class
val dialog = DialogClassSample.newInstance()//show dialog description according to user type
dialog.show(activity?.supportFragmentManager?.beginTransaction(), DialogClassSample::class.java.name)
In on resume we have set dialog size dynamically ,because in some bigger size dialog its look not good so you can use as per your requiremnent
I'm trying to implement an empty state recycler view based on this post. I have migrated the solution to Kotlin, but the problem is I'm not able to extend CustomRecyclerView.Adapter (Adapter is an abstract class defined in RecyclerView) from the newly defined custom recycler view in Kotlin. And I have observed the same CustomRecyclerView.Adapter can be extended in Java.
Custome RecyclerView implementation
open class CustomRecyclerView: RecyclerView {
private var emptyStateView : View? = null
constructor(context: Context) : super(context)
constructor(context: Context , attrs: AttributeSet) : super(context,attrs)
constructor(context: Context , attrs: AttributeSet, defstyle: Int) : super(context,attrs,defstyle)
var observer: AdapterDataObserver = object : AdapterDataObserver() {
override fun onChanged() {
super.onChanged()
initEmptyView()
}
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
super.onItemRangeRemoved(positionStart, itemCount)
initEmptyView()
}
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
super.onItemRangeInserted(positionStart, itemCount)
initEmptyView()
}
}
private fun initEmptyView() {
emptyStateView?.let {
it.visibility = if (adapter == null || adapter!!.itemCount == 0) View.VISIBLE else View.GONE
this#CustomRecyclerView.visibility = if (adapter == null || adapter!!.itemCount == 0) View.GONE else View.VISIBLE
}
}
override fun setAdapter(adapter: Adapter<*>?) {
val oldAdapter = getAdapter()
super.setAdapter(adapter)
oldAdapter?.unregisterAdapterDataObserver(observer)
adapter?.registerAdapterDataObserver(observer)
}
/**
* #param emptyView is the view which is going to display when the recycler view is empty
* **/
fun setEmptyView(emptyView: View) {
this.emptyStateView = emptyView
initEmptyView()
}}
Adding images for the extension implementation in java and kotin
To summarise the comments: inherit from RecyclerView.Adapter, see below
YourAdapter: RecyclerView.Adapter<YourViewHolder>()
And just a hint, here's the Kotlin way to extend a class with multiple constructors:
class CustomRecyclerView #JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : RecyclerView(context, attrs, defStyleAttr)
For more info, check #JvmOverloads
It should be RecyclerView.Adapter.. and set adapter to customRecyclerView.