【问题标题】:How to nest a RadioGroup with dynamic lists of RadioButton inside each row/item of a RecyclerView如何在 RecyclerView 的每一行/项目中嵌套带有 RadioButton 动态列表的 RadioGroup
【发布时间】:2015-11-05 21:03:56
【问题描述】:

我需要这样的布局:

红色标题是来自dish_options 的第一级数组,RadioButtons 是从 json 的 itemsinside dish_options 数组中填充的:

您可能注意到dish_options 是一个数组,它可能在此dish_options 的一个键中包含更多对象,可能存储items 数组。

我尝试使用getItemViewType() 并为第一级dish_options(红色标题)设置不同的布局,并在items 的每一行中为RadioButton 实现了不同的布局@问题是我必须使用 RadioGroup 来使 RadioButton 独一无二(每个无线电组仅单击 1 次)。所以我被这个困住了,不知道如何继续。

我应该在 RecyclerView 的每一行中嵌套一个 RecyclerView 吗?

【问题讨论】:

    标签: android android-layout android-adapter android-recyclerview android-radiogroup


    【解决方案1】:

    你可以试试这个代码https://github.com/h6ah4i/android-advancedrecyclerview

    这是一个具有 groupSection 或 GroupItem 的单个适配器,由一个 recyclerView 维护 因为您的设计并不太复杂,这可能会有所帮助

    首先按原样运行“draggable with section”...然后根据需要更改布局

    您可能需要删除可拖动界面及其方法,因为我猜您不需要它们

    implements DraggableItemAdapter<DraggableWithSectionExampleAdapter.MyViewHolder>

    仔细看看这个类,你可能需要以这种方式集成你的 JSON 数据,或者在这个类中(如果你不是专家,我建议你)注释行第 37 - 53 行并尝试与你的复制数据

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

    由于您需要从组中选择一些或无项目,...您可以实现一个复选框或切换图像并将 0 设置为未选中或 1 为选中到您的数据类(我的意思是您的您从 JSON 生成的 POJO 类,或者您甚至可以在 json 中维护一个键)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-31
      • 1970-01-01
      • 2021-06-01
      • 2018-11-03
      • 1970-01-01
      • 2020-12-05
      • 2020-07-05
      • 1970-01-01
      相关资源
      最近更新 更多