首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android:可扩展的Listview -从远程数据库加载子内容

问Android:可扩展的Listview -从远程数据库加载子内容
EN

Stack Overflow用户
提问于 2015-05-09 12:07:59
回答 1查看 551关注 0票数 0

我有一个具有组头的ExpandableListView,它不会改变。现在,我想用来自远程数据库(如MySQL或MSSQL )的不同数据绑定该组的子组。对于使用ListView的普通JSON,我已经这样做了,我不知道如何为ExapandableListView实现它。

请帮帮忙。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-17 19:28:01

我知道答案了。我创建了三个不同的ArrayList,一个用于标题的List<String>和一个HashMap。我使用ArrayList填充了AsyncTask。然后,根据一个特定的值,我将值添加到每个ArrayList中,并将子数组和头数组添加到HashMap中,如下所示。

代码语言:javascript
复制
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();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30139716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档