How to nest a RadioGroup with dynamic lists of RadioButton inside each row/item of a RecyclerView

爷,独闯天下 提交于 2019-12-13 08:47:18

问题


I need a layout like this:

The Red titles are the first level array from dish_options and the RadioButtons are a populated from an array itemsinside dish_options of the json:

As you may notice the dish_options is an array, which might have many more object inside one of the keys of this dish_options might store an items arrays.

I tried using getItemViewType() and set different layouts for first level dish_options (red title) and implemented a different layout for the RadioButton in each row of itemsthe problem is that I have to use RadioGroup to make RadioButton unique (only 1 click per radiogroup). So I'm stucked with this and no idea how to proceed.

Should I nest a RecyclerView inside each row of the RecyclerView?


回答1:


you can give a try to this code https://github.com/h6ah4i/android-advancedrecyclerview

This is a single adapter having groupSection or GroupItem maintained with one recyclerView because your design is not too much complex thismight be helpful

first run "draggable with section" as it is ... and then change the layout as per your need

you may need to remove the draggable interface with its methods as I guess you don't need them

implements DraggableItemAdapter<DraggableWithSectionExampleAdapter.MyViewHolder>

Carefully have a look at this class and you might need to integrate your JSON data some how in this way, or inside this classes(I suggest if your not an expert) comment line no 37 - 53 and atry to replicate with your data

https://github.com/h6ah4i/android-advancedrecyclerview/blob/master/example/src/main/java/com/h6ah4i/android/example/advrecyclerview/common/data/ExampleSectionDataProvider.java

As you required to select some or None Items from the group, ... you can implement a check-box or switch the images and set the 0 for unchecked or 1 for checked to your data class (I'm mean your POJO class you generated from JSON or you can even maintain a key in json )



来源:https://stackoverflow.com/questions/33554740/how-to-nest-a-radiogroup-with-dynamic-lists-of-radiobutton-inside-each-row-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!