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

  • SEARCH
  • Home
  • 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 6635941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:07:15+00:00 2026-05-25T23:07:15+00:00

I need to be able to create and delete groups in my expandableListAdapter dynamically.

  • 0

I need to be able to create and delete groups in my expandableListAdapter dynamically. I have looked through all that I can find and am stuck. I do not need specific code, but just to be pointed in the right direction.

  • 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-25T23:07:16+00:00Added an answer on May 25, 2026 at 11:07 pm

    First, we need some data structures (keep a reference to them for later use).

    headerData = new ArrayList<HashMap<String, String>>();
    childData = new ArrayList<ArrayList<HashMap<String, Object>>>();
    

    headerData is the list of groups – HashMap is used since each group can have multiple display values, each of which is mapped onto the layout by key.

    childData is the list of items belonging to each group. Its a list of lists, each containing HashMaps – similar to the groups, each child can have multiple display values which are mapped by key.

    We supply these datastructures to our ExpandableListAdapter on creation. We’re also telling the adapter how the display values should be mapped; in this example both groups and children have two display values, keys “name” and “fields” which are mapped onto text1 and text2 in the supplied layouts.

    adapter = new SimpleExpandableListAdapter( SearchLogs.this, 
            headerData, R.layout.customlayout_group,
            new String[] { "name", "fields" }, new int[] { R.id.text1, R.id.text2 }, 
            childData, R.layout.customlayout_child, 
        new String[] { "name", "fields" }, new int[] { R.id.text1, R.id.text2 } );
    setListAdapter(adapter);   // assuming you are using ExpandableListActivity
    

    Up to this point we have an empty ExpandableList. We can populate it dynamically (using an AsyncTask for example) by creating HashMaps that supply values for keys we are using and then adding them to our lists.

    For example, to add a group with a couple children we might …

    HashMap<String, String> group = new HashMap<String, String>();
    group.put("name", "whatever...");
    group.put("fields", "...");
    
    ArrayList<HashMap<String, Object>> groupChildren = new ArrayList<HashMap<String, Object>>();
    
    HashMap<String, Object> child1 = new HashMap<String, Object>();
    child1.put("name", "child name");
    child1.put("fields", "...");
    
    HashMap<String, Object> child2 = new HashMap<String, Object>();
    child2.put("name", "another child");
    
    groupChildren.add(child1);
    groupChildren.add(child2);
    
    headerData.add(group);
    childData.add(groupChildren);
    

    Each HashMap in headerData corresponds (by order) to an ArrayList in childData, which contains additional HashMaps that define the actual children. SO even if you are adding an empty group, remember to add a corresponding (empty) ArrayList to childData.

    We just added a group to the end of the list – we can just as easily insert as long as we are mindful to insert into the same position in both headerData and childData. Removing groups is the same – be certain to remove from the same position of both headerData and childData.

    Finally, notify the adapter that the data has changed, which will cause the List to refresh. If using an AsyncTask, this must be done outside of doInBackground (use onProgressUpdate in this case).

    adapter.notifyDataSetChanged();
    

    I hope this helps you move in the right direction. ExpandableList, in terms of how data is stored, is definitely one of the more complicated Android views.

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

Sidebar

Related Questions

I need to create a configuration section, that is able to store key-value pairs
Haven't seen anything, but I have seen that you can create albums in the
all; I'd like to be able to create a new document in Dreamweaver that
I have a RichTextBox that the user can edit to create a hyperlink (in
I'm trying to create a script that will delete all user properties for a
I need to be able to create basic MS Project items (tasks, projects, resources,
I need to be able to create a UserSession without having the decrypted password.
I need to be able to create a seperate function which creates a total
In order to create the proper queries I need to be able to run
I am attempting to create a table in rails.. I need to be able

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.