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.
int lastExpandedGroupPosition = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ExpandableListView listView = (ExpandableListView) findViewById(R.id.listView);
listView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
// TODO Auto-generated method stub
if (groupPosition != lastExpandedGroupPosition) {
listView.collapseGroup(lastExpandedGroupPosition);
}
lastExpandedGroupPosition = groupPosition;
}
});
adapter = new ExpandableListAdapter(this, new ArrayList<String>(),
new ArrayList<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"