Android:可扩展列表视图 - 从远程数据库加载 Child 内容

Android: Expandable Listview - Load Child content from remote database

我有一个 ExpandableListView 组 headers,不会改变。现在我想将组的 children 与来自远程数据库的不同数据绑定,例如 MySQLMSSQL。我已经使用 JSON 为普通 ListView 完成了此操作,我不知道如何为 ExapandableListView 实现它。

请帮忙。

谢谢

我得到了答案。我创建了三个不同的 ArrayList,一个 List<String> 用于 header,一个 HashMap。我使用 AsyncTask 填充了 ArrayList。然后根据一个特定值,我将值添加到每个 ArrayList 并将 child 数组列表和 header 数组列表添加到 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();
}