android / views-widgets-samples

Multiple samples showing the best practices in views-widgets on Android.
Apache License 2.0
5.04k stars 3.01k forks source link

ViewPager2 weird behaviour with ListAdapter and conditionals #124

Open justdeko opened 4 years ago

justdeko commented 4 years ago

I used a simple ListAdapter with a RecyclerView.Viewholder for my ViewPager2 and noticed quite a few weird things happened. If i used a conditional in the setup of my itemview (bind method that's called in onBindViewHolder) like so if (item.id == 1) itemView.removeButton.hide()

the remove button actually appeared for each fifth (???) element, despite the condition only triggering once. After inverting it. and quickly removing items from the ViewPager2 (via submitting a new list into the listadapter) when arriving onto the last item left, the remove button shows up (while it shouldn't).

I can only assume this has something to do with view recycling for faster rendering, but I can't seem to figure out what the actual issue can be.