How do I get the position selected in a RecyclerView?

前端 未结 13 2472
自闭症患者
自闭症患者 2020-11-27 04:40

I am experimenting with the support library\'s recyclerview and cards. I have a recyclerview of cards. Each card has an \'x\' icon at the top right corner to remove it:

13条回答
  •  粉色の甜心
    2020-11-27 04:52

    When using data binding and you need to know a RecyclerView click position from inside of an item's click listener:

    Kotlin

        val recyclerView = view.parent as RecyclerView
        val position = recyclerView.getChildAdapterPosition(view)
    

提交回复
热议问题