Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access the viewholder of an item in a recycler view?

I have got a recycler view that shows a list of images. I have added an onScrollListener to that recycler view.

Now, when a scroll is detected, I would like to set the translation of the imageviews in the viewholders. Therefore I need a reference to the underlying view holders.

How can I get those?

In code (this won't work, but you will get the idea what I want to achieve):

ImageView imageView = (ImageView) ((RecyclerFragmentAdapter.MyViewHolder) 
    mRecyclerView.getChildAt(i)).itemView.findViewById(R.id.imageView);
// ... Modify imageview, i.e. imageView.setImageMatrix(customImageMatrix);
like image 948
user2426316 Avatar asked Sep 05 '25 03:09

user2426316


1 Answers

RecyclerView.getChildViewHolder()
RecyclerView.findViewHolderForAdapterPosition()
RecyclerView.findViewHolderForLayoutPosition()
like image 106
Neil Avatar answered Sep 07 '25 23:09

Neil