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

I am looking for api like isExpanded () or isCollapsed () which tell me if the group is expanding or reset.

+6
source share
3 answers

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; } }); 

You can find more information here.

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

+9
source

The ExpandableListAdapter has a parameter in getGroupView() , a boolean value that represents whether 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 this group. This view is intended only for the group - views for the children of the group will be retrieved using getChildView (int, int, boolean, View, ViewGroup)).

Options

groupPosition the position of the group for which the view is being returned

isExpanded: expand or group group

convertView is an old view for reuse, if possible. You must ensure that this representation is not null and of the appropriate type before use. 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 convertView will be previously created by getGroupView (int, boolean, View, ViewGroup). parent parent who will eventually be attached to

+1
source

As @George D wrote that there is an ExpandableListView .isGroupExpanded(int groupPosition) . Well, you can add code to get an 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; } 
0
source

Source: https://habr.com/ru/post/983449/


All Articles