簡體   English   中英

如何用ArrayList中的數據填充ExpandableListView?

[英]How to populate ExpandableListView with data from ArrayList?

我設法從數據庫中檢索數據並將其存儲在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");

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM