ExpandableListView Android中的键顺序 [英] Ordering of keys in expandablelistview android

查看:55
本文介绍了ExpandableListView Android中的键顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个哈希图,并按照要在可扩展列表视图中显示的顺序在其中添加键.下面是将字符串放入哈希图中的代码:

I am creating a hashmap and adding keys in it in the order i want to display in expandable listview. Below is the code for putting string in hashmap:

HashMap<String, List<String>> example= new HashMap<String, List<String>>();
        example.put(cnt.getString(R.string.first), first_summary);
        example.put(cnt.getString(R.string.second), second_summary);
        example.put(cnt.getString(R.string.third), third_summary);

但是当我将其添加到列表视图中时,第二个要比第一个更早.如何按定义键的顺序插入expandablelistview?

But when i am adding it to listview then second is coming before first.How can i insert in expandablelistview in the order i have defined the keys?

以下是可扩展列表视图创建的代码:

Below is the code for expandablelistview creation:

 public View getGroupView(int parent, boolean isExpanded, View convertview, ViewGroup parentview) {
    // TODO Auto-generated method stub
    String group_title = (String) getGroup(parent);
    if(convertview == null)
    {
        LayoutInflater inflator = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertview = inflator.inflate(R.layout.parent_layout, parentview,false);
    }
    TextView parent_textview = (TextView) convertview.findViewById(R.id.parent_txt);
    parent_textview.setTypeface(null, Typeface.BOLD);
    parent_textview.setText(group_title);
    return convertview;
}

你能指导吗?..

推荐答案

这不是ExpandableListView的错.HashMap没有顺序的概念.尝试使用 LinkedHashMap .来自文档

It's not ExpandableListView's fault .HashMap has not the notion of order. Try using a LinkedHashMap. From the doc

LinkedHashMap是Map的实现,可确保迭代 命令.支持所有可选操作.

LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations are supported.

这篇关于ExpandableListView Android中的键顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆