Skip to content Skip to sidebar Skip to footer

Duplicates In My ExpandableListView Adapter

the problem goes is that everytime I add more than one Child to a GroupItem in my ExpandableListView, the item duplicates itself with the previous child. I have narrowed it down to

Solution 1:

@Override
public int getChildCount(.....)
{
     return 2;
}

If you are sure that for every item there are only 2 subitems
Sorry my bad this is the right method you want.
EDIT

@Override
public int getChildrenCount(int groupPosition)
{
    return (rCollection.get(weekdata.get(groupPosition())).size();
}

This will return the size (length) of your List<Custom> for a map.
balance paranthesis if needed


Solution 2:

am not sure if you found a solution but here is what worked for me; since i was returning a recyclerview in the child view, just return 1 in getChildrenCount() method.

That's it


Solution 3:

I dug it out of some old repo, I think this is what I ended up doing.

public int getChildrenCount(int groupPosition) {
    // Fixes a bunch of NPE when the groupPosition = NULL. This way it checks and returns 0 when it = null. 
    List<MySQLWeek> group = rCollection.get(weekData.get(groupPosition));

        if (group == null){
        return 0;
        }

        return group.size();


}

Post a Comment for "Duplicates In My ExpandableListView Adapter"