您好我关注了json回复
我想在listview中设置标题的标题,在子列表视图中设置静态文本作为内容。但问题是我只能设置标题,但其内容设置不正确。任何人都可以帮助我吗?
我正在关注这个例子
https://w2davids.wordpress.com/android-sectioned-headers-in-listviews/
try {
for (int i = 0; i < response.length(); i++) {
JSONObject person = (JSONObject) response
.get(i);
System.out.println("Product Response" + person);
JSONArray itemlist = person.optJSONArray("staticInfoDetails");
JSONArray policyDetails = person.optJSONArray("policyDetails");
JSONArray otherDetailsAndroid = person.optJSONArray("otherDetailsAndroid");
for (int j = 0; j < itemlist.length(); j++) {
JSONObject itmobj = (JSONObject) itemlist
.get(j);
JSONArray sections=itmobj.optJSONArray("staticDetails");
subcat_list=new ArrayList<String>();
for(int a=0;a<sections.length();a++)
{
JSONObject secitmobj = (JSONObject) sections
.get(a);
// subcat_list.add(secitmobj.getString("sortID"));
subcat_list.add(secitmobj.getString("staticText"));
// subcat_list.add(secitmobj.getString("staticPath"));
}
moreheaderlist.add(itmobj.getString("title"));
}
for (int j = 0; j < policyDetails.length(); j++) {
JSONObject itmobj = (JSONObject) policyDetails
.get(j);
moreheaderlist.add(itmobj.getString("title"));
JSONArray sections=itmobj.optJSONArray("staticDetails");
for(int a=0;a<sections.length();a++)
{
JSONObject secitmobj = (JSONObject) sections
.get(a);
// subcat_list.add(secitmobj.getString("sortID"));
subcat_list.add(secitmobj.getString("staticText"));
// subcat_list.add(secitmobj.getString("staticPath"));
}
}
for (int j = 0; j < otherDetailsAndroid.length(); j++) {
JSONObject itmobj = (JSONObject) otherDetailsAndroid
.get(j);
moreheaderlist.add(itmobj.getString("title"));
}
}
adapter = new SeparatedListAdapter(MoreActivity.this);
ArrayAdapter<String> listadapter = new ArrayAdapter<String>(MoreActivity.this, R.layout.list_item, subcat_list);
// Add Sections
for (int a = 0; a < moreheaderlist.size(); a++)
{
adapter.addSection(moreheaderlist.get(a), listadapter);
}
journalListView.setAdapter(adapter);
System.out.println("Product Response" + subcat_list);
} catch (JSONException e) {
e.printStackTrace();
/* Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_SHORT).show();*/
System.out.println("ProductList Response Error"+e.getMessage());
}
例如我想要输出这样的
答案 0 :(得分:1)
你可以尝试使用ExpendableListView这样的例子