Search code examples
javaandroidlistviewexpandablelistviewexpandable

Expandable List View items without Group


I'm trying to implement an expandable list view for a navigation drawer menu. I was wondering if there was a way to make it so that only one of the items in the menu could expand? For example, opening the navigation drawer menu would yield

A
B
C
->C1
->C2
->C3
D

So, C would be the only group while A, B, and D would just be singular items that don't have any children. Anyone have any insight into this?


Solution

  • You can do that. just map the child to only the "C" which are c1, c2, etc. And replace

       @Override
    public int getChildrenCount(int groupPosition) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .size();
    }
    

    this in ExpandableListAdapter with

      @Override
    public int getChildrenCount(int groupPosition) {
        try {
            return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                    .size();
        } catch (NullPointerException e) {
            e.printStackTrace();
            return 0;
        }
    }
    

    this will return 0 child count for A, B, D etc.