0

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?

htafoya
  • 18,261
  • 11
  • 80
  • 104
  • 1. Does this form has a lot of fields inside so you should use RecyclerView? 2. RadioButtons are spread vertically so one radiobutton per one row or one row can have multiple radiobuttons? – Mike Jan 10 '20 at 00:08
  • Not that much, I was just thinking that yesterday, probably it's best to build it around a LinearLayout – htafoya Jan 10 '20 at 16:35

0 Answers0