Let's say I have a RecyclerView
which represents an application Form. It may have several fields for EditTexts, selectors, checkboxes, radios, etc.
Because the RadioButtons
need to be grouped into a RadioGroup
in order to deselect the other radios of the group, I was thinking that the ViewHolder
for Radio fields would consist of a RadioGroup which programatically adds the radio options, rather than creating individual ViewHolders for each RadioButton and managing the deselection on other rows of the same group.
In order to achieve this, I was thinking that whenever the Viewholder is bound, I'll have to clear the RadioGroup from any buttons and add them again, so that if several RadioGroups are used in the scroll and some of them are recycled, no additional radios are shown.
This works but I'm not really happy with the solution, as it defeats the purpose of the RecyclerView.
Is there a better or cleaner way to do this?