im using expanded listview in my project, i need to expand the listview only one at a time, ie i expand a item and when try to expand another item in the list the previous item which i expanded has to collapse and the new item clicked has to expand, Answers will be greatly appreciated, i'm trying with the below snippet for the on click listener..
convertViewpar.setOnClickListener(new OnClickListener() {
int i=1;
public void onClick(View v) {
i = i++;
int[] expds = new int[100];
expds[0]=0;
expds[i] = groupPosition;
if(expds[i]==expds[i-1]){
if(isExpanded)
expandlist.collapseGroup(i);
else
expandlist.expandGroup(i);
}else{
expandlist.collapseGroup(i-1);
if(isExpanded)
expandlist.collapseGroup(i);
else
expandlist.expandGroup(i);
}
}
});
Add implements OnGroupExpandListener at class level and in onCreate Method
listView.setOnGroupExpandListener(this);
and add this method
/*
* (non-Javadoc)
*
* @see
* android.widget.ExpandableListView.OnGroupExpandListener#onGroupExpand
* (int)
*/
public void onGroupExpand(int groupPosition) {
int len = expListAdapter.getGroupCount();
for (int i = 0; i < len; i++) {
if (i != groupPosition) {
listView.collapseGroup(i);
}
}
}
It will works definitely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With