2

我设法从数据库中检索数据并将其存储在 ArrayList 中:

ArrayList<Category> selectCategory = select.all().from(Category.class).execute();

    for (Category category: selectCategory) {
        builder.append(category.name).append("\n");
    }

现在我想将该数据添加到 ExpandableListView 的子元素。以下代码是硬编码的,我不希望这样。我希望它从数据库中获取数据。我怎么做?

List<String> class1= new ArrayList<String>();
    class1.add("English");
    class1.add("Maths");
    class1.add("Geo");
4

1 回答 1

0

http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/

我使用本教程创建了我自己的 ExpandableListAdapter。基本上,您需要一个所有父项的列表和一个附加的 Hashmap,其中父项为键,子项为 List<>。

List<Parent> parentList = new ArrayList<>();
HashMap<Parent, List<Child>> childHashMap = new HashMap<Parent, List<Child>>
于 2015-02-16T13:38:00.313 回答