How to check if group is expanded or collapsed in Android ExpandableListView?

前端 未结 4 2389
感动是毒
感动是毒 2021-02-20 04:13

I\'m looking for an api like isExpanded() or isCollapsed() that tell me if a group is expanded or collapsed.

4条回答
  •  Happy的楠姐
    2021-02-20 04:42

    As @George D wrote there is ExpandableListView .isGroupExpanded(int groupPosition) method. Well you could add the code to get expanded group position or -1

    public int getExpandedGroupPosition() {
        for (int i = 0; i < listView.getExpandableListAdapter().getGroupCount(); i++) {
            if ( listView.isGroupExpanded(i) ) {
                return i;
            }
        }
    
        return -1;
    }
    

提交回复
热议问题