Dynamic ExpandableListView

Posted by JLB on Stack Overflow See other posts from Stack Overflow or by JLB
Published on 2010-06-08T16:29:40Z Indexed on 2010/06/08 16:32 UTC
Read the original article Hit count: 317

Filed under:

Can anyone tell me how I can Dynamically add groups & children to an ExpandableListView. The purpose is to create a type of task list that I can add new items/groups to.

I can populate the view with pre-filled arrays but of course can't add to them to populate the list further. The other method i tried was using the SimpleExpandableListAdapter. Using this i am able to add groups from a List but when it comes to adding children i can only add 1 item per group.

public List<Map<String, String>> groupData = new ArrayList<Map<String, String>>(); public List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();

public void addGroup(String group) { Map curGroupMap = new HashMap(); groupData.add(curGroupMap);

    curGroupMap.put(NAME, group);

    //Add an empty child or else the app will crash when group is expanded. 
    List<Map<String, String>> children = new ArrayList<Map<String, String>>();
    Map<String, String> curChildMap = new HashMap<String, String>();
    children.add(curChildMap);
    curChildMap.put(NAME, "EMPTY");

    childData.add(children);

    updateAdapter();

}

 public void addChild(String child) {

List> children = new ArrayList>(); Map curChildMap = new HashMap(); children.add(curChildMap); curChildMap.put(NAME, child); curChildMap.put(IS_EVEN, "This child is even");

    childData.add(activeGroup, children);

    updateAdapter();

}

© Stack Overflow or respective owner

Related posts about android