我有一个具有组头的ExpandableListView,它不会改变。现在,我想用来自远程数据库(如MySQL或MSSQL )的不同数据绑定该组的子组。对于使用ListView的普通JSON,我已经这样做了,我不知道如何为ExapandableListView实现它。
请帮帮忙。
谢谢
发布于 2015-05-17 19:28:01
我知道答案了。我创建了三个不同的ArrayList,一个用于标题的List<String>和一个HashMap。我使用ArrayList填充了AsyncTask。然后,根据一个特定的值,我将值添加到每个ArrayList中,并将子数组和头数组添加到HashMap中,如下所示。
JSONObject responseObj = null;
listDataChild = new HashMap<String, List<PatPrescriptionList>>();
try {
Gson gson = new Gson();
responseObj = new JSONObject(response);
JSONArray patPrescListObj = responseObj.getJSONArray("patPrescriptionList");
ArrayList<PatPrescriptionList> patPrescList_MedClerking = new ArrayList<PatPrescriptionList>();
for (int i=0; i<patPrescListObj.length(); i++){
JSONObject patPrescInfo = patPrescListObj.getJSONObject(i);
if(patPrescInfo.optString("PRTYPCode").equals("CC_MEDCLERK")){
PatPrescriptionList patPresc = gson.fromJson(patPrescInfo.toString(), PatPrescriptionList.class);
patPrescList_MedClerking.add(patPresc);
}
else if(patPrescInfo.optString("PRTYPCode").equals("CC_FORADMIN")){
PatPrescriptionList patPresc = gson.fromJson(patPrescInfo.toString(), PatPrescriptionList.class);
patPrescList_InpatMedication.add(patPresc);
}
else if(patPrescInfo.optString("PRTYPCode").equals("CC_LVMED")){
PatPrescriptionList patPresc = gson.fromJson(patPrescInfo.toString(), PatPrescriptionList.class);
patPrescList_LeaveMedication.add(patPresc);
}
else if(patPrescInfo.optString("PRTYPCode").equals("CC_DISCHMED")){
PatPrescriptionList patPresc = gson.fromJson(patPrescInfo.toString(), PatPrescriptionList.class);
patPrescList_DischargeMedication.add(patPresc);
}
else if(patPrescInfo.optString("PRTYPCode").equals("CC_OPCLERK")){
PatPrescriptionList patPresc = gson.fromJson(patPrescInfo.toString(), PatPrescriptionList.class);
patPrescList_OutpatClerking.add(patPresc);
}
else if(patPrescInfo.optString("PRTYPCode").equals("CC_OP_FORADMIN")){
PatPrescriptionList patPresc = gson.fromJson(patPrescInfo.toString(), PatPrescriptionList.class);
patPrescList_OutpatMedication.add(patPresc);
}
}
listDataChild.put(listDataHeader.get(0),patPrescList_MedClerking);
listDataChild.put(listDataHeader.get(1),patPrescList_InpatMedication);
listDataChild.put(listDataHeader.get(2),patPrescList_LeaveMedication);
listDataChild.put(listDataHeader.get(3),patPrescList_DischargeMedication);
}
listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);
expListView.setAdapter(listAdapter);
}
catch (JSONException e) {
e.printStackTrace();
}https://stackoverflow.com/questions/30139716
复制相似问题