折叠组在多级可扩展列表视图中不起作用
Collapse group doesn't work in multilevel expandable list view
我有一个多层次ExpandableListView
。我一次只需要扩展一个项目。在第二关,我用过这个方法,但是没有用:
simpleExpandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
if (lastExpandedPositions != -1 && groupPosition != lastExpandedPositions) {
simpleExpandableListView.collapseGroup(lastExpandedPositions);
// getChildView
}
lastExpandedPositions = groupPosition;
}
});
为什么方法 collapseGroup(lastExpandedPositions)
没有响应?
有人可以帮忙吗??
我的问题已解决,答案在下面的代码中我将此代码添加到一级可扩展列表适配器的 getchildView() 方法中:
int lastExpandedPositions=-1;
simpleExpandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View view,
int groupPosition, long id) {
setListViewHeight(parent, groupPosition);
parent.smoothScrollToPosition(groupPosition);
// Need default behaviour here otherwise group does not get expanded/collapsed
if (parent.isGroupExpanded(groupPosition)) {
parent.collapseGroup(groupPosition);
} else {
parent.expandGroup(groupPosition);
if (lastExpandedPositions != -1
&& groupPosition != lastExpandedPositions) {
parent.collapseGroup(lastExpandedPositions);
}
lastExpandedPositions = groupPosition;
}
return true;
}
});
我有一个多层次ExpandableListView
。我一次只需要扩展一个项目。在第二关,我用过这个方法,但是没有用:
simpleExpandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
if (lastExpandedPositions != -1 && groupPosition != lastExpandedPositions) {
simpleExpandableListView.collapseGroup(lastExpandedPositions);
// getChildView
}
lastExpandedPositions = groupPosition;
}
});
为什么方法 collapseGroup(lastExpandedPositions)
没有响应?
有人可以帮忙吗??
我的问题已解决,答案在下面的代码中我将此代码添加到一级可扩展列表适配器的 getchildView() 方法中:
int lastExpandedPositions=-1;
simpleExpandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View view,
int groupPosition, long id) {
setListViewHeight(parent, groupPosition);
parent.smoothScrollToPosition(groupPosition);
// Need default behaviour here otherwise group does not get expanded/collapsed
if (parent.isGroupExpanded(groupPosition)) {
parent.collapseGroup(groupPosition);
} else {
parent.expandGroup(groupPosition);
if (lastExpandedPositions != -1
&& groupPosition != lastExpandedPositions) {
parent.collapseGroup(lastExpandedPositions);
}
lastExpandedPositions = groupPosition;
}
return true;
}
});