lastExpandedGroupPosition

lastExpandedGroupPosition

当我扩展一个新组时,我可以折叠最后一个扩展的组吗?

最佳答案

尝试将其放在ExpandableListAdapter中,listView是对ExpandableListView本身的引用。 lastExpandedGroupPosition是在ExpandableListAdapter内部定义的整数成员变量。

    @Override
    public void onGroupExpanded(int groupPosition){
        //collapse the old expanded group, if not the same
        //as new group to expand
        if(groupPosition != lastExpandedGroupPosition){
            listView.collapseGroup(lastExpandedGroupPosition);
        }

        super.onGroupExpanded(groupPosition);
        lastExpandedGroupPosition = groupPosition;
    }

10-06 07:28