Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't recycle specific view type in RecyclerView

I have a recycler view which is reusing view, my problem is that one viewholder contains a ViewPager and, if the recyclerview's adapter reuse the view where the viewholder is inflated then an exception occurs on the viewpager. However, the onCreateViewHolder method is only called the first time. How could I avoid this behaviour and achieve that the onCreateViewHolder can be called more than once?

Thanks in advance

like image 294
FVod Avatar asked Nov 09 '16 15:11

FVod


People also ask

Is recycler view bound single view or multiple view?

Android RecyclerView Multiple ViewType Project Structure Each has its own implementation specified in the adapter class.

Which methods you would override if you have to implement a RecyclerView having different types of views provide proper method names?

You will have to override two main methods: one to inflate the view and its view holder, and another one to bind data to the view. The good thing about this is that the first method is called only when we really need to create a new view. No need to check if it's being recycled.

What is ViewHolder in RecyclerView Android?

A ViewHolder describes an item view and metadata about its place within the RecyclerView. Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive findViewById results. While LayoutParams belong to the LayoutManager , ViewHolders belong to the adapter.


1 Answers

use recyclerView.getRecycledViewPool().setMaxRecycledViews(YOUR_VIEW_TYPE, 0); This will disable recycling of the specified view type

like image 108
Ognian Gloushkov Avatar answered Sep 18 '22 13:09

Ognian Gloushkov