我有以下JSON格式
{
"listing": {
"attribute": [{
"name": "brand",
"data": [{
"value": "brand with subtitle"
}, {
"value": "Brand2"
}, {
"value": "Samsung"
}]
}, {
"name": "price",
"data": [{
"value": 12
}, {
"value": 1499
}]
}, {
"name": "color",
"data": [{
"value": "Red"
}, {
"value": "Green"
}]
}, {
"name": "size",
"data": [{
"value": "XXXL"
}, {
"value": "L"
}]
}]
}
}
在上面的格式中有两个数组属性和数据。所以我对属性数组包含多个名字,我想在listview中显示,所以我成功完成了这个任务,见下图
但是里面有特定名称的数据数组列表,我想在右侧列表视图中显示arraylist值意味着如果我点击品牌那时品牌的价值会在右边显示侧面列表视图。我完成了左侧列表项的代码
if (mGetProductListing.getListing().getAttribute().size() > 0) {
mainMenuDataArrayList = getData();
if (mainMenuDataArrayList.size() > 0) {
mFilterCateAdapter = new FilterCateAdapter(ActivityFilter.this, mainMenuDataArrayList);
mListViewLeft.setAdapter(mFilterCateAdapter);
mFilterCateAdapter.setSelectedIndex(0);
}
}
但是,我如何根据选择类别动态列出右侧列表项?你的所有建议都很明显
答案 0 :(得分:0)
private List<Attribute> attributeList;
private List<AttributeData> dataList;
initialise both lists in constructor of adapter.
This list contains your json response under tag "attribute" that has "name" and "data"
In your custom list adapter under getView() method,
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(attributeList.get(position) != null && !attributeList.get(position).getDataList().isEmpty) {
dataList.addAll(attributeList.get(position).getDataList);
//Now pass dataList list to the fragment on the right.
}
}
});