【问题标题】:Expandable Listview with ArrayList<HashMap<String,String>>带有 ArrayList<HashMap<String,String>> 的可扩展列表视图
【发布时间】:2015-01-21 18:59:55
【问题描述】:

我想用 CarList 作为 childList,这样 HashMap 是列表的一行,组字符串是表头。我怎样才能将它们组合在一起。我还需要一个适配器来使用这些。

以下代码是我目前所拥有的。

    ArrayList<HashMap<String, String>> CarList;

            static final String TAG_URLS = "urls";
            static final String TAG_ID = "id";
            static final String TAG_NAME = "name";
            static final String TAG_PIC = "pic";
            String group;

    CarList = new ArrayList<HashMap<String, String>>();

List<Cars> cars = db.getAllCars();       
String group = "Cars";
        for (Cars cn : cars) {

    HashMap<String, String> map = new HashMap<String, String>();

                                String id = String.valueOf(cn.getID());
                                String name = cn.getName();
                                String urls = cn.getUrls();
                                String pic = cn.getPic();

                                map.put(TAG_ID, id);
                                map.put(TAG_NAME, name);
                                map.put(TAG_URLS, urls);
                                map.put(TAG_PIC, pic);

                                CarList.add(map);
}

【问题讨论】:

  • 你想要3个级别吗?

标签: android string arraylist expandablelistview expandablelistadapter


【解决方案1】:

如果你想使用不同的值类型,你可以使用下一个模式:

创建一个值对象,它将包含所有视图类型的所有信息,我们称之为MyDataItem。比创建一个'MyDataItem'的arrayList。确保“MyDataItem”属性中的一个是类型,这样就可以区分标题和内部项之间的区别,以及您的结构是什么。

您可以使用 BaseAdapter 的下一个方法来处理:

        @Override
        public int getViewTypeCount() {
            return super.getViewTypeCount();
        }

        @Override
        public int getItemViewType(int position) {
            return super.getItemViewType(position);
        }

这将允许您在一个列表中管理多种类型的视图。您可以在this 手册中找到更多信息。

【讨论】:

    猜你喜欢
    • 2014-05-27
    • 1970-01-01
    • 2013-07-29
    • 2012-07-13
    • 1970-01-01
    • 1970-01-01
    • 2017-08-30
    • 2013-05-27
    • 1970-01-01
    相关资源
    最近更新 更多