Skip to content Skip to sidebar Skip to footer

Expandabelistview Auto Collapse

I am not able to close a previously expanded group on expanding a new group. I have read similar questions, but I'm unable to extract concept from them. I tried using the collapseG

Solution 1:

Hi Please try below code.


intlastExpandedGroupPosition=0;   

@OverridepublicvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    finalExpandableListViewlistView= (ExpandableListView) findViewById(R.id.listView);

    listView.setOnGroupExpandListener(newOnGroupExpandListener() {

        @OverridepublicvoidonGroupExpand(int groupPosition) {

            // TODO Auto-generated method stubif (groupPosition != lastExpandedGroupPosition) {
                listView.collapseGroup(lastExpandedGroupPosition);

            }
            lastExpandedGroupPosition = groupPosition;

        }
    });

    adapter = newExpandableListAdapter(this, newArrayList<String>(),
            newArrayList<ArrayList<Vehicle>>());

    // Set this blank adapter to the list view
    listView.setAdapter(adapter);


}

import below line.


import android.widget.ExpandableListView.OnGroupExpandListener;

Post a Comment for "Expandabelistview Auto Collapse"