Search code examples
androidlistexpandable

Android list with one expandable item


is there possibility to make list with only one expandable item ? I found many samples and tutorials how to make expandable list with all items expandable.


Solution

  • Yes, you can use the ExpandableListView and the ExpandableListAdapter, and then implement the getChildrenCount method on ExpandableListAdapter this way:

    @Override
    public int getChildrenCount(int groupPosition) {
        if(groupPosition == <THE EXPANDABLE POSITION>) {
             return <number of items>
        } else {
             return 0;
        }
    }
    

    Doing this, only the group in will be expandable.