【发布时间】:2014-01-04 05:40:43
【问题描述】:
我尝试为我的应用程序添加可扩展列表视图。该列表包括标题和子列表。
对于列表,使用 Web 服务加载的数据。
我使用Android Expandable List View Tutorial 链接进行开发。
我已成功加载标题列表。但情况是,子列表包括数组列表中的所有数据。我只想加载与标题相关的内容。
例如:它显示酒店名称和所有酒店详细信息,再次显示酒店名称和所有酒店详细信息。
它通过网络服务成功加载数据。我只想处理arrayList。
这是我使用的代码。
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);
}
谁能帮帮我?
【问题讨论】:
标签: android android-layout arraylist expandablelistview expandablelistadapter