Skip to content Skip to sidebar Skip to footer

Adding Dynamic Children To ExpandableListView (as Records Are Added)

I need to dynamically add children to expandable list view. AFter i add my record in addshare activity, i go to another activity(dynamic1) passing a String object. Over here i add

Solution 1:

Alright, after checking your entire code I've seen that you initialize your custom adapter this way:

// notice that it's an empty constructor
MyCustomAdapter c = new MyCustomAdapter();

Looking at your MyCustomAdapter.java I've found there are two constructors for this class. One is the empty constructor and the other is this:

// You should use this one instead
public MyCustomAdapter(Context context, ArrayList<parent> parent){
         mParent = parent;
         c = context;
         inflater = LayoutInflater.from(context);
}

In your dynamic1 activity you initialize the c with the empty constructor which doesn't receive parent and context, hence when you call:

int  i = c.getChildrenCount(0);

You'll get NPE because the parent is null. To sort it out, instantiate the c with correct constructor:

MyCustomAdapter c = new MyCustomAdapter(YourActivityContext, ParentArrayList);

Solution 2:

It appears that you never assigned an Adapter so the list doesn't have one to return to you. Look at this tutorial on how to implement a SimpleExpandableListAdapter.


Post a Comment for "Adding Dynamic Children To ExpandableListView (as Records Are Added)"