What adapter shall I use to use HashMap in a ListView

后端 未结 6 1578
轮回少年
轮回少年 2020-11-27 04:42

I want to use HashMap for a list of items of Adapter for a ListView. I was going to use ArrayAdapter<> but I can\'t

6条回答
  •  粉色の甜心
    2020-11-27 05:23

    To maintain order in the dictionary, if the key type is applicable, you could always add them to an ArrayList of their own, sort it using Collections.sort, and work with that as your reference point.

    private ArrayList mKeys = new ArrayList<>();
    
    for (String aKey :data.keySet()){
            mKeys.add(aKey);
        }
    Collections.sort(mKeys);
    

提交回复
热议问题