Android ExpandableListView From Database
- by SterAllures
I want to create a two level ExpandableListView from a local database.
The group level I want to get the names from the database Category table
category_id | name
-------------------
    1       | NameOfCategory
the children level I want to get the names from the List table
list_id |   name   | foreign_category_id
--------------------------------
   1    | Listname |     1 
I've got a method in DatabaseDAO to get all the values from the table
public List<Category> getAllCategories()
{
    database = dbHelper.getReadableDatabase();
    List<Category> categories = new ArrayList<Category>();
    Cursor cursor = database.query(SQLiteHelper.TABLE_CATEGORY, null, null, null, null, null, null);
    cursor.moveToFirst();
    while(!cursor.isAfterLast())
    {
        Category category = cursorToCategory(cursor);
        categories.add(category);
        cursor.moveToNext();
    }
    cursor.close();
    return categories;
}
Now adding the names to the group level is easy I do it the following way:
ArrayList<String> groups;
for(Category c : databaseDao.getAllCategories())
            {
                groups.add(c.getName());
            }
Now I want to add the children to the ExpandableListView in the following array ArrayList<ArrayList<ArrayList<String>>> children;.
How do I get the children under the correct group name?
I think it has to do somenthing with groups.indexOf() but in the list table I only have a foreign category_id and not the actual name.