tags:

views:

69

answers:

0

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<String, String> curGroupMap = new HashMap<String, String>();
    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<Map<String, String>> children = new ArrayList<Map<String, String>>();
    Map<String, String> curChildMap = new HashMap<String, String>();
    children.add(curChildMap);
    curChildMap.put(NAME, child);
    curChildMap.put(IS_EVEN, "This child is even");


    childData.add(activeGroup, children);

    updateAdapter();
}