i have this function to setup the Recyclerview:
fun setUpRecyclerview() {
clickToPatch()
mAdapter.updateData(plannersList)
recyclerView!!.layoutManager =
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
recyclerView?.adapter = mAdapter
swipeToDelete()
}
and this is click to patch function:
fun clickToPatch() {
recyclerView?.addOnItemTouchListener(object : RecyclerView.SimpleOnItemTouchListener() {
var downTouch = false
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
when (e.action) {
MotionEvent.ACTION_DOWN -> downTouch = true
MotionEvent.ACTION_UP -> if (downTouch) {
downTouch = false
recyclerView!!.findChildViewUnder(e.x, e.y)?.let {
val position = rv.getChildAdapterPosition(it)
val id: Int = mAdapter.plannersList?.get(position)!!.id
showPatchIbadahDialog(id)
}
}
else -> downTouch = false
}
return super.onInterceptTouchEvent(rv, e)
}
})
}
so when i click the item in emulator i it work fine and i can patch the item but when i try to click the item on physical phone, nothing happen and clicking on the item isn't responsive
what am i doing wrong here?
UPDATE:
onBindViewHolder:
override fun onBindViewHolder(holder: ItemBaseViewHolder, position: Int) {
holder.bind(plannersList?.get(position)!!)
}
CodePudding user response:
You can set clickListeners
for each items of your recyclerView
inside bind
method of your viewHolder
class.
class PlannerListhHolder(private val plannerListBinding: PlannerItemBinding) :
RecyclerView.ViewHolder(plannerListBinding.root) {
fun bind(plannerItem: PlannerItem) {
plannerListBinding.root.setOnClickListener {
//show your dialog
}
}
}