I'm trying to make extended list view with android and this is my json result .
[
{
eCode: 0,
Menu_Cat_Id: 1,
Menu_Cat_Name: "Salaaad",
photo: "http://awtuts.com/restaurant/uploads/categories/2.jpg",
subCategories: [
{
Item_Id: 1,
Item_NameAR: "شيش طاووق",
Item_NameEN: "SHeeeeeeesh",
Item_size: "Larg",
Item_Prc: 100,
Item_Photo: "http://awtuts.com/restaurant/uploads/subcategories/1.jpg"
},
{
Item_Id: 1,
Item_NameAR: "شيش طاووق",
Item_NameEN: "SHeeeeeeesh",
Item_size: "Small",
Item_Prc: 10,
Item_Photo: "http://awtuts.com/restaurant/uploads/subcategories/1.jpg"
}
]
},
{
eCode: 0,
Menu_Cat_Id: 2,
Menu_Cat_Name: "Salaaad",
photo: "http://awtuts.com/restaurant/uploads/categories/2.jpg",
subCategories: [
]
}
]
and my android code is :
protected void onPostExecute(String result) {
try {
Parent recievedUser;
Parent child;
ArrayList<Parent> listDataHeader = new ArrayList<Parent>();
List<String> parents = new ArrayList<>();
ArrayList<Parent> listChildData = new ArrayList<Parent>();
List<String> children = new ArrayList<>();
JSONArray jsonArray = new JSONArray(result);
JSONArray jsonArrayChild=new JSONArray(result);
for (int i = 0; i < jsonArray.length(); i++) {
jsonObject = jsonArray.getJSONObject(i);
recievedUser = new Parent();
child=new Parent();
recievedUser.setMenu_Cat_Id(jsonObject.getInt("Menu_Cat_Id"));
recievedUser.setMenu_Cat_Name(jsonObject.getString("Menu_Cat_Name"));
recievedUser.setPhoto(jsonObject.getString("photo"));
child.setItem_NameEN(jsonObject.getString("Item_NameEN"));
listDataHeader.add(recievedUser);
listChildData.add(child);
}
// set list adapter
ExpandableListAdapter expandableListAdapter = new ExpandableListAdapter(MainActivity.this, listDataHeader, listChildData);
expListView.setAdapter(expandableListAdapter);
But i have an exception and have a problem with children list . I have tried alot of things but they didn't work with me , please can any body help me to find the wrong thing with my code ?
Try something like this: