RecyclerView 项目点击在模拟器上工作,但在 kotlin 中不在物理上

RecyclerView item click is working on emulator but not on physical in kotlin

我有这个功能来设置 Recyclerview:

fun setUpRecyclerview() {
    clickToPatch()
    mAdapter.updateData(plannersList)
    recyclerView!!.layoutManager =
        LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
    recyclerView?.adapter = mAdapter
    swipeToDelete()

}

这是点击补丁功能:

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)
        }
    })

}

因此,当我在模拟器中单击该项目时,它工作正常并且我可以修补该项目,但是当我尝试在物理 phone 上单击该项目时,没有任何反应并且单击该项目没有响应

我做错了什么?

更新:

onBindViewHolder:

override fun onBindViewHolder(holder: ItemBaseViewHolder, position: Int) {
    holder.bind(plannersList?.get(position)!!)

}

您可以在 viewHolder class.

bind 方法中为 recyclerView 的每个项目设置 clickListeners
class PlannerListhHolder(private val plannerListBinding: PlannerItemBinding) :
            RecyclerView.ViewHolder(plannerListBinding.root) {
            fun bind(plannerItem: PlannerItem) {
                plannerListBinding.root.setOnClickListener {
                    //show your dialog
                }
            }
        }