getAdapterPosition() not returning position of item in RecyclerView

后端 未结 2 1814
野趣味
野趣味 2021-01-05 04:51

This is a sort of follow-up or complement to this post. I am trying to get the position of an item in my RecyclerView, but none of the methods I have tried have worked.

相关标签:
2条回答
  • 2021-01-05 05:26

    Can I get the click event using the viewHolder.mView.setOnClickListener() and then the viewHolder.getAdapterPosition () to get the position. How can I do to get some data from the item I'm clicking, for example the name.

    Example complet here:

    https://pastebin.com/TuKTchNi

    0 讨论(0)
  • 2021-01-05 05:39

    Call getAdapterPosition() in your onClick() method because then at the time of the click you want to know the position of the item. If you check at the time of the creation it will (most of the times) be inaccurate.

    0 讨论(0)
提交回复
热议问题