2015-10-18 72 views
1

我正在創建一個hashmap,並且按照我想要在可擴展列表視圖中顯示的順序添加按鍵。下面是把字符串HashMap中的代碼:在可擴展列表視圖中按鍵的排序android

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); 

但是,當我加入它的ListView然後第二first.How之前來我可以在我所定義的按鍵順序expandablelistview插入?

下面是expandablelistview創建代碼:

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; 
} 

你能引導請..

回答

3

這不是ExpandableListView的錯? HashMap沒有訂單的概念。嘗試使用LinkedHashMap。從文檔

LinkedHashMap是一個Map的實現,保證了迭代次數 的順序。所有可選操作均受支持。