FVod FVod - 1 year ago 90
Android Question

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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download