I need to get a reference to a specific row within my recyclerView
.
I used to do it like this
View row = recyclerView.childAt(position);
since the childAt()
method is based on the ViewGroup
, once the list is scrolled, the positions are messed up.
I read here I had to use recyclerView.findViewHolderForAdapterPosition()
which returns a ViewHolder
.
How do I get from the ViewHolder
to the actual View
I need to work with?
Your should use findViewByPosition
findViewByPosition(int position)
Finds the view which represents the given adapter position.
View row = recyclerView.getLayoutManager().findViewByPosition(YourPosition);
You can get the view from the ViewHolder using its public itemView
member variable:
RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(position);
final View itemView = viewHolder.itemView;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With