Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7675605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:59:57+00:00 2026-05-31T16:59:57+00:00

I want to create a two level ExpandableListView from a local database. The group

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:59:58+00:00Added an answer on May 31, 2026 at 4:59 pm

    I’ve got the following which kinda works now.

    I’ve created a rawQuery to get get the list names grouped with the category in rows.

    public List<CategoryAndLists> getCategoryAndListNames()
    {
        database = dbHelper.getReadableDatabase();
        List<CategoryAndLists> calList = new ArrayList<CategoryAndLists>();
        Cursor cursor = database.database.rawQuery("SELECT c.category_id, c.name, w.name FROM category AS c, lists AS w WHERE c.category_id = w.category_id ORDER BY c.category_id, w.name", null);
    
        cursor.moveToFirst();
        while(!cursor.isAfterLast())
        {
            CategoryAndLists categoryAndLists = new CategoryAndLists();
            categoryAndLists.setCategory(cursor.getString(0));
            categoryAndLists.setWishlist(cursor.getString(1));
    
            System.out.println(cursor.getString(0));
            System.out.println(cursor.getString(1));
    
            calList.add(categoryAndLists);
    
            cursor.moveToNext();
        }
    
        return calList;
    }
    

    And changed the loadData() method to the following:

    private void loadData(){
    
            groups= new ArrayList<String>();
            children= new ArrayList<ArrayList<ArrayList<String>>>();
    
            int childrenIndex = 0;
            String lastCategory = "";
    
    
            for(Category c : databaseDao.getAllCategories())
            {
                if(!groups.contains(c.getName()))
                {
                    groups.add(c.getName());
                }   
            }
    
            for(CategoryAndLists c : databaseDao.getCategoryAndListNames())
            {
                if(!children.contains(c.getWishlist()))
                {
    
                        if(lastCategory.equals(c.getCategory()))
                        {
                            childrenIndex++;
                            System.out.println("childrenIndex++ Called");
                        }
                        else
                        {
                            childrenIndex = 0;
                            System.out.println("childrenIndex = 0 Called");
                        } 
    
                    //Get the groups ArrayList index id to add the children to
                    int index = groups.indexOf(c.getCategory());
    
                    System.out.println("INDEX CHILDRENINDEX: " +childrenIndex);
    
                    children.add(new ArrayList<ArrayList<String>>());
                    children.get(index).add(new ArrayList<String>());
                    children.get(index).get(childrenIndex).add(c.getWishlist());
    
                    childrenIndex++;
                }
    
            }
    

    I’m going to do a couple of test runs but for now this works and I can’t think of any other solution, if someone has some input, it’s more than welcome.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a view from the following two tables: Entry: entry_id entry_date
I want to create two widgets in flex. One for the movies ( that
I want to create two and three dimensional vectors using a constructor in a
i am preparing my android apps in which i want to create two row
I want to create a two-dimensional array in which I want to store records
If I want to do bi-directional mapping, do I need to create two mapping?
I have two ImageIcons and I want to create a third ImageIcon which has
I want to create a view that contains two forms with their submit buttons.
I want to create an array which has two columns. The output should contain
i want to create a polymorphic Queue association. I have two different queues in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.