Recyclerview.adapter Resets Radio-buttons
Solution 1:
I know that this was answered already but if some of you are still looking for an easier answer and your application does not rely on the RecyclerView view recycling feature much (for example if you have a fixed size list of items...) you can always set your recycler view cache view size. That way it would not recycler your views hence it would not recycler the views and you will avoid copy selected values to another views...
yourRecyclerView..setItemViewCacheSize(yourItemList.size());
Solution 2:
Save the checked / unchecked status of the radio button (you should use checkbox instead if you want to allow the user to select multiple items) to your model (i.e. your items in the list should have a field for this) when the onClick event happens. When you bind the ViewHolder, make sure you set checkbox's value to whatever you saved in your model.
Solution 3:
It's happen because of the Recycling mechanism
(PS: its the same for the ListView or RecyclerView).
To fix that:
1) Add a
booelanvariable to your model to save the state of theRadioButton2) Update your
RadioButtonstate inonBindViewHolder()method from thisbooleanin the model.3) Add
setOnCheckedChangeListener()to yourRadioButtonto listen to his state (checked/unchecked) and to update the boolean in your model when the state changes.

Post a Comment for "Recyclerview.adapter Resets Radio-buttons"