如何获取Hashmap列表值

时间:2017-05-24 07:07:28

标签: android hashmap adapter expandablelistview

这是我对可扩展列表视图的试用版,我想在适配器中设置文本,但它不适用于我

 listDataHeader = new ArrayList<String>();
                            listDataChild = new HashMap<String, List<String>>();
                            JSONArray jsonObject = response.getJSONArray("data");
                            for (int i = 0; i < jsonObject.length(); i++) {
                                JSONObject object1 = jsonObject.getJSONObject(i);
                                listDataHeader.add(object1.getString("title"));
                                List<String> lease_offer = new ArrayList<String>();
                                lease_offer.add(object1.getString("name"));
                                lease_offer.add(object1.getString("tips"));
                                listDataChild.put(listDataHeader.get(i), lease_offer);
                                listAdapter = new ExpandableListAdapter(getApplicationContext(), listDataHeader, listDataChild);

适配器: -

public class ExpandableListAdapter extends BaseExpandableListAdapter {

        private Context _context;
        private List<String> _listDataHeader; // header titles
        // child data in format of header title, child title
        private HashMap<String, List<String>> _listDataChild;

        public ExpandableListAdapter(Context context, List<String> listDataHeader,
                                     HashMap<String, List<String>> listChildData) {
            this._context = context;
            this._listDataHeader = listDataHeader;
            this._listDataChild = listChildData;
        }

        @Override
        public Object getChild(int groupPosition, int childPosititon) {
            return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                    .get(childPosititon);
        }

        @Override
        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

        @Override
        public View getChildView(int groupPosition, final int childPosition,
                                 boolean isLastChild, View convertView, ViewGroup parent) {

            final String childText = (String) getChild(groupPosition, childPosition);

            if (convertView == null) {
                LayoutInflater infalInflater = (LayoutInflater) this._context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = infalInflater.inflate(R.layout.list_item, null);
            }

            TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem);
            WebView ImageCild = (WebView) convertView.findViewById(R.id.Imagess);



            ImageCild.loadData(childText,"text/html; charset=utf-8",null);
            return convertView;
        }

但我无法理解如果我有2个textview然后如何从hashmap中检索特定值,那么哪些数据会出现在子文本中?

txtListChild.setText(childText.getname());

如何在hashmap中设置这些?

请帮帮我,我在android中使用第一次hashmap

0 个答案:

没有答案