Android 在listView中合并相同项目的最佳方式是什么?

Android 在listView中合并相同项目的最佳方式是什么?,android,algorithm,listview,arraylist,Android,Algorithm,Listview,Arraylist,我有一个lisView,其中一些项目可能具有类似的属性,我想要: 首先找到了这些具有类似属性的项 第二个,将它们合并到列表视图的一行项目中 及 最后选中项目后,在展开的布局中显示其项目(已合并) 我的想法不是很强,我想使用for循环找到类似的项目,然后将它们存储在数组中,最后在适配器中检查项目是否为合并的类型,然后使用可扩展布局 有更好的解决方案吗?考虑使用HashMap HashMap<String, ArrayList<Item>> map = new HashMap

我有一个
lisView
,其中一些项目可能具有类似的属性,我想要:

首先找到了这些具有类似属性的项

第二个,将它们合并到列表视图的一行项目中

最后选中项目后,在展开的布局中显示其项目(已合并)

我的想法不是很强,我想使用
for
循环找到类似的项目,然后将它们存储在
数组中,最后在
适配器中检查项目是否为合并的
类型
,然后使用
可扩展布局


有更好的解决方案吗?

考虑使用HashMap

HashMap<String, ArrayList<Item>> map = new HashMap<String, ArrayList<Item>>();
for (int i = 0; i < listOfItems.size(); i++) {
        if(map.containsKey(listOfItems.get(i).property){
          map.get(listOfItems.get(i).property).add(listOfItems.get(i));
        }else{
          ArrayList temp = new ArrayList();
          temp.add(listOfItems.get(i);
          map.put(listOfItems.get(i).property, listOfItems.get(i))
       }
    }
map.get(property)