user2426316
user2426316

Reputation: 7331

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);

Upvotes: 4

Views: 4849

Answers (1)

Neil
Neil

Reputation: 664

RecyclerView.getChildViewHolder()
RecyclerView.findViewHolderForAdapterPosition()
RecyclerView.findViewHolderForLayoutPosition()

Upvotes: 6

Related Questions