Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a custom indicator for ExpandableListView isn't working

So I'm trying to set a custom ExpandableListView indicator icon but it isn't working. I created an icon and saved it to drawable folder. Here are the icons:

enter image description hereenter image description here

This is the selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/arrow_up" android:state_empty="true"/>
    <item android:drawable="@drawable/arrow_down" android:state_activated="true"/>
</selector>

ExpandableListView xml:

<ExpandableListView
    android:id="@+id/lvExp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:groupIndicator="@drawable/custom_arrow" />

However, when I launch the app, there is not indicator at all. Any idea what I have done wrong?

like image 245
Guy Avatar asked Sep 19 '13 20:09

Guy


1 Answers

this should do the trick

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_expanded="true" android:drawable="@drawable/arrow_up" />
    <item android:drawable="@drawable/arrow_down" />
</selector>

you wanted the state_expanded for when the row gets expanded and then any other state besides expanded is just the normal down arrow. You should however handle the state_empty when there is nothing to expand to

like image 142
tyczj Avatar answered Sep 17 '22 13:09

tyczj