javaandroidandroid-recyclerviewandroid-radiobutton

android - Single RadioButton in RecyclerView


I have a RecyclerView with item that holds RadioButton only, my adapter creates RecyclerView with some positions - can be 5-10 positions with RadioButton in every position. But these RadioButtons are not in the same RadioGroup because they are all in different RecyclerView positions. Is there any way to set single selection for it?

PS: I found this Select only one radiobutton in a recyclerview, but it's all about RadioGroups in RecyclerView positions, I have RadioButtons only.


Solution

  • You can manage it by creating a model class with a boolean variable isChecked.

    when you select a RadioButton first do isChecked = false for all and then make true for your selected button and then call notifyDataSetChanged.

    In adapter use

    radioButton.setChecked(list.get(position).isChecked())
    

    It will help you definitely.