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
Android RecyclerView Multiple ViewType Project Structure Each has its own implementation specified in the adapter class.
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.
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.
use recyclerView.getRecycledViewPool().setMaxRecycledViews(YOUR_VIEW_TYPE, 0);
This will disable recycling of the specified view type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With