RecyclerView - Get view at particular position
If you want the View
, make sure to access the itemView
property of the ViewHolder like so: myRecyclerView.findViewHolderForAdapterPosition(pos).itemView;
I suppose you are using a LinearLayoutManager
to show the list. It has a nice method called findViewByPosition
that
Finds the view which represents the given adapter position.
All you need is the adapter position of the item you are interested in.
edit: as noted by Paul Woitaschek in the comments, findViewByPosition
is a method of LayoutManager
so it would work with all LayoutManagers (i.e. StaggeredGridLayoutManager
, etc.)
This is what you're looking for.
I had this problem too. And like you, the answer is very hard to find. But there IS an easy way to get the ViewHolder from a specific position (something you'll probably do a lot in the Adapter).
myRecyclerView.findViewHolderForAdapterPosition(pos);
NOTE: If the View has been recycled, this will return null
. Thanks to Michael for quickly catching this omission. Furthermore, if the user is scrolling quickly, the view can be recycled even after you obtain this ViewHolder, causing all kinds of problems. So be careful when using this technique, especially if you're doing relatively slow work like changing the look of the View(s).