ExpandableListView有很多项,展开一项则另一个展开的项关闭, 就像两个项互斥。每次只能有一个项目是展开的。
重载onGroupExpand函数,做一下控制就好了,代码如下:
//复写Adapter方法,
//isGroupExpanded(groupPosition)&collapseGroup(i) 都是ExpandableListView的方法,最好将此对象以参数传递
方法一:
[java] view
plaincopyprint?
重载onGroupExpand函数,做一下控制就好了,代码如下:
@Override
public void onGroupExpand(int groupPosition) {
// TODO Auto-generated method stub
for (int i = 0; i < mArtistAdapter.getGroupCount(); i++) {
// ensure only one expanded Group exists at every time
if (groupPosition != i &&isGroupExpanded(groupPosition)) {
collapseGroup(i);
}
}
}
方法二:
实现
[java] view
plaincopyprint?
ExpandableListView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
for (int i = 0; i < mProductClassFirstAdapter.getGroupCount(); i++) {
// ensure only one expanded Group exists at every
if (groupPosition != i) {
mProductFirstListView.collapseGroup(i);
}
}
}
});