我正在使用排球库制作可扩展列表视图。我已经获取了所有工作正常的根类别。现在我必须映射子类别。我
不知道我该怎么解决。这是我的json响应代码:here is my child categories
JSONArray headerArray = object.getJSONArray("ListCategories");
for (int i=0;i<headerArray.length();i++){
JSONObject jsonObject = headerArray.getJSONObject(i);
final int Id = jsonObject.getInt("CategoryID");
final String name = jsonObject.getString("CategoryName");
header.add(new Category(Id,name));
JSONArray childArray = headerArray.getJSONObject(index++).getJSONArray("ListChildCategories");
for (int j=0;j<childArray.length();j++){
JSONObject childObject = childArray.getJSONObject(i);
final int ChildId = childObject.getInt("ID");
final String ChildName =
jsonObject.getString("Name");
child.add(new ChildCategory(ChildId,""));
}
Log.e("childArray",childArray.toString());
}
adapter = new ExpandableCategoryAdapter(context,header,child);
expandableListView.setAdapter(adapter);
adapter.notifyDataSetChanged();
这是我的类别模型:
public int getId() {
return Id;
}
public void setId(int id) {
Id = id;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
这是子类别的模型:
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public int getId() {
return Id;
}
public void setId(int Id) {
this.Id = Id;
}