How to check if group is expanded or collapsed in

2020-07-06 05:43发布

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

4条回答
迷人小祖宗
2楼-- · 2020-07-06 05:57

There is a parameter in getGroupView() on your ExpandableListAdapter, a boolean that represents wheter the group is expanded or not.

From (http://developer.android.com/reference/android/widget/ExpandableListAdapter.html#getGroupView(int, boolean, android.view.View, android.view.ViewGroup)

Gets a View that displays the given group. This View is only for the group--the Views for the group's children will be fetched using getChildView(int, int, boolean, View, ViewGroup)).

Parameters

groupPosition the position of the group for which the View is returned

isExpanded whether the group is expanded or collapsed

convertView the old view to reuse, if possible. You should check that this view is non-null and of an appropriate type before using. If it is not possible to convert this view to display the correct data, this method can create a new view. It is not guaranteed that the convertView will have been previously created by getGroupView(int, boolean, View, ViewGroup). parent the parent that this view will eventually be attached to

查看更多
地球回转人心会变
3楼-- · 2020-07-06 06:06

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;
}
查看更多
虎瘦雄心在
4楼-- · 2020-07-06 06:13

If u use BaseExpandableListAdapter class you have getGroupView() override method.

public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {

    // Here is your expand list view parent id
    // b specify that parent expand or not.

    .............

    if(b){
        imdDownArrow.setVisibility(View.GONE);
        imdUpArrow.setVisibility(View.VISIBLE);
    }else{
        imdDownArrow.setVisibility(View.VISIBLE);
        imdUpArrow.setVisibility(View.GONE);
    }
    ...............
    return view;
}

so using this simple code you can show arrow up or down

查看更多
冷血范
5楼-- · 2020-07-06 06:15

You can use isGroupExpanded .

 expListViewObj.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

                @Override
                public boolean onGroupClick(ExpandableListView parent, View v,
                                            int groupPosition, long id) {

                    if(parent.isGroupExpanded(groupPosition))
                    {

                     // Do your Staff
                    }
                    else{

                       // Expanded ,Do your Staff

                    }


                    return false;
                }
            });

For more details you can visit Here

http://developer.android.com/reference/android/widget/ExpandableListView.html#setOnGroupClickListener(android.widget.ExpandableListView.OnGroupClickListener)

查看更多
登录 后发表回答