2

I managed to retrive data from the database and store it in ArrayList:

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

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

Now I want to add that data to child element of ExpandableListView. The following code is hardcoded, and I don't want it that way. I want it to get data from database. How do I do that?

List<String> class1= new ArrayList<String>();
    class1.add("English");
    class1.add("Maths");
    class1.add("Geo");
mirta
  • 644
  • 10
  • 25
  • That you can do in the same way with `class1.add()`. What is builder? You should have given it's definition and instantiation too. – greenapps Feb 16 '15 at 13:23
  • So your problem is not how to populate the ExpandableListView but how to get data from a database? – Deutro Feb 16 '15 at 13:29
  • @greenapps builder is: StringBuilder builder = new StringBuilder(); – mirta Feb 16 '15 at 13:33
  • @Deutro I managed to get data, becuase I tryed to print it on the screen with Toast and it works. I just don't know how to store it in child element of Expandable list view.... – mirta Feb 16 '15 at 13:34

1 Answers1

0

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

I used this tutorial to create my own ExpandableListAdapter. Basically you need a list of all parent items and an additional Hashmap with the parent as key and the child as List<>.

List<Parent> parentList = new ArrayList<>();
HashMap<Parent, List<Child>> childHashMap = new HashMap<Parent, List<Child>>
Deutro
  • 3,113
  • 4
  • 18
  • 26
  • I used the same tutorial. Thanks for the effort, but in this tutorial strings are hardcoded, and they are printed on the screen when you start the app. It works perfectly that way for me too. But I want to get that strings from my database, not have them hardcoded. I want to do something like class1.add(category.getFromDB). Sorry if I am not explaining it right. I just started learning android... – mirta Feb 16 '15 at 14:55
  • Do you know how to get the data from your database. I am currently working with an API where I get my data from so I can not help you with this unfortunately. So your first problem is to get data from the database, right? – Deutro Feb 16 '15 at 15:19