Hide expandable list if no children

Found some similar questions, but no answers that work. Now I am doing this:

private ExpandableListView elv;
elv.setGroupIndicator(getResources().getDrawable(R.drawable.expandable_list_icon_selector));

expandable_list_icon_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_empty="true" android:drawable="@android:color/transparent"/>
</selector>

Unfortunately, this hides the indicator for all groups, even if they are not empty. It seems that when the group is not expanded, the android considers it empty. Any tips? Thank.

+3
source share
5 answers

EDIT: This method does not work by design ( source ).

Have you tried to add a non-empty state?

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_empty="true"
          android:state_expanded="false"
          android:drawable="@android:color/transparent"/>
    <item android:drawable="@drawable/some_image"/>
</selector>
0
source

- - . , , setGroupIndicator(null). BaseExpandableListAdapter getGroupView() . , . , .

+1

, :

if(explistView != null){
     explistView.setIndicatorBounds(0, 0);
}
-1

*

in getGroupView() method of adapter  use 

if ( getChildrenCount( groupPosition ) == 0 ) {
       indicator.setVisibility( View.INVISIBLE );
    } 
else {`enter code here`
       indicator.setVisibility( View.VISIBLE );
       indicator.setImageResource( isExpanded ? R.drawable.group_expanded : R.drawable.group_closed );
    }

*

-1

All Articles