I tried to add Expandable List View for my application. That list include header and sub list.
for the list, data loaded by using web service.
i used Android Expandable List View Tutorial link for develop this.
i loaded header list successfully. but the case is, the sublist include all data in array list. i want to load only the things which related with the header.
for an example: it display hotel name and all hotels details, again hotel name and all hotels details.
It successfully load the data through the web service. i just want to handle the arrayList.
This is code i used.
public void ListDrwaer() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
List<String> restData = new ArrayList<String>();
try {
JSONObject jsonResponse = new JSONObject(strJson1);
JSONArray jsonMainNode = jsonResponse.optJSONArray("restaurants");
for (int i = 0; i < jsonMainNode.length(); i++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
String restName = jsonChildNode.optString("name");
String address = jsonChildNode.optString("address");
String mobile = jsonChildNode.optString("mobile");
String direction = jsonChildNode.optString("direction");
String bestTime = jsonChildNode.optString("bestTime");
String food = jsonChildNode.optString("food");
String dress = jsonChildNode.optString("dress");
String priceRange = jsonChildNode.optString("priceRange");
listDataHeader.add(restName);
restData.add(address);
restData.add(mobile);
restData.add(direction);
restData.add(bestTime);
restData.add(food);
restData.add(dress);
restData.add(priceRange);
listDataChild.put(listDataHeader.get(i), restData);
}
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "Error..." + e.toString(),
Toast.LENGTH_LONG).show();
}
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
expListView.setAdapter(listAdapter);
}
Can anyone help me?