http://blog.csdn.net/judy50/article/details/53334907 这篇文章的方法可以解决,但是是先展开点击的分组,再收之前的,打开新的分组后显示位置有问题,在这个基础上做了调整
//设置分组项的点击监听事件
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
for (int i = 0; i < expandableListviewAdapter.getGroupCount(); i++) {
if (groupPosition != i && expandableListView.isGroupExpanded(i)) {
//关闭已打开的分组
expandableListView.collapseGroup(i);
}
}
//切换点击的分组状态 打开/关闭
if (expandableListView.isGroupExpanded(groupPosition)){
expandableListView.collapseGroup(groupPosition);
}else {
expandableListView.expandGroup(groupPosition);
}
// true 拦截
return true;
}
});