开发者

Collapsing previously expanded Group, when new Group has been expanded in ExpandableListView

开发者 https://www.devze.com 2023-02-17 04:12 出处:网络
I\'m using ExpandableListView. i have a around 100 groups in the list, and 10-15 childrens for each group.

I'm using ExpandableListView. i have a around 100 groups in the list, and 10-15 childrens for each group.

now my problem is, whenever i expand a new Group , i want the previously expanded group to be closed. is there a way to do this. Please anyone tell me whether it is possible to do thi开发者_C百科s..

Thank u


You can use the ExpandableListView.OnGroupExpandListener. Maintain the previously expanded groupPosition and use collapseGroup(groupPosition) to close the group.


Very well, we have to maintain previous group integer by final or static variable


expandableList.setOnGroupExpandListener(new OnGroupExpandListener() {
    int previousItem = -1;

    @Override
    public void onGroupExpand(int groupPosition) {
        if(groupPosition != previousItem ) {
            expandableList.collapseGroup(previousItem );
        }
        previousItem = groupPosition;
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消