我遇到了问题。我习惯于此代码折叠可扩展列表视图android中除选定组以外的所有组:
mExpandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
if (lastExpandedPosition != -1 && groupPosition != lastExpandedPosition) {
mExpandableListView.collapseGroup(lastExpandedPosition);
}
lastExpandedPosition = groupPosition;
}
});
但是某些组是空的,因此我希望单击空组不会关闭其他组。 谢谢
答案 0 :(得分:0)
尝试一下:
mExpandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
ExpandableListViewAdapter adapter = (ExpandableListViewAdapter)mExpandableListView.getAdapter();
if (adapter.getChildrenCount(groupPosition) > 0) {
if (lastExpandedPosition != -1 && groupPosition != lastExpandedPosition) {
mExpandableListView.collapseGroup(lastExpandedPosition);
}
lastExpandedPosition = groupPosition;
}
}
});
请更改适配器类型以匹配您的适配器类型。希望有帮助!