【发布时间】:2020-07-29 08:27:39
【问题描述】:
我想填充一个嵌套的 ArrayList。 下面是来自服务器的 JSON 响应。现在我希望 sectionName 作为 headerView 和 sectionItems 作为该标题的子视图。所以,这个布局看起来像分类项目。 我已经研究过同样的问题,但找不到任何简单有效的解决方案。我不想创建一个单独的展平列表,因为这会花费我时间。 现在,我怎样才能实现这种布局。 PS:我不想使用任何外部库。
"data": [
{
"sectionName": "Fruits",
"sectionItems": [
{
"id": "123",
"name": "Apple",
"image": "url",
"price": "120",
"quntity": "600gm"
},
{
"id": "234",
"name": "Orange",
"image": "url",
"price": "340",
"quntity": "2kg"
},
{
"id": "334",
"name": "Banana",
"image": "url",
"price": "340",
"quntity": "2kg"
}
]
},
{
"sectionName": "Paints",
"sectionItems": [
{
"id": "345",
"name": "Red",
"image": "url",
"price": "120",
"quntity": "1l"
},
{
"id": "346",
"name": "White",
"image": "url",
"price": "120",
"quntity": "1l"
},
{
"id": "347",
"name": "Purple",
"image": "url",
"price": "120",
"quntity": "1l"
}
]
}
【问题讨论】:
-
扁平化成本真的值得解决这个简单的问题吗?
-
@MariuszBrona 不多,但我想找到一种替代方法。因为我想学习。
标签: android arraylist android-recyclerview nested nestedlayout