Show only one child of expandable list at a time

steve-gregory picture steve-gregory · Oct 22, 2011 · Viewed 24.7k times · Source

Is it possible to only expand one child of an ExpandableListView at a time, thus opening a second child would close the previously opened child?

Answer

Blundell picture Blundell · Apr 6, 2013

Just to confirm bos's answer in code:

    expandableList.setOnGroupExpandListener(new OnGroupExpandListener() {
        int previousGroup = -1;

        @Override
        public void onGroupExpand(int groupPosition) {
            if(groupPosition != previousGroup)
                expandableList.collapseGroup(previousGroup);
            previousGroup = groupPosition;
        }
    });