Android – Hide drawable for expandable list when there are no children

androidexpandablelistview

Found some similar questions but no answers that work. Right 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 appears that when a group is not expanded, android considers it empty. Any tips? Thanks.

Best Solution

I did something similar to your task - to show a custom group indicator next to the group name of only some of the groups. I did it by first hiding the group indicator at all using the method setGroupIndicator(null). Then I implemented a subclass of BaseExpandableListAdapter and inside the getGroupView() method I showed or hid my own indicator image based on my logic. You may use such an approach, if that is still current. I hope I helped you.

Related Question