gpt4 book ai didi

android - 折叠组在多级可扩展 ListView 中不起作用

转载 作者:行者123 更新时间:2023-11-29 01:06:00 25 4
gpt4 key购买 nike

我有一个多级 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;
}
});

关于android - 折叠组在多级可扩展 ListView 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47169425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com