Put on the right the indicator of an ExpandableListView in Android

One more solution is: 1) First set groupIndicator in your ExpandableListView to @null:

<ExpandableListView [...] 
    android:groupIndicator="@null" />

2) Then create group_indicator.xml file with following details:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/down_icon" android:state_selected="false"></item>
    <item android:drawable="@drawable/up_icon" android:state_selected="true"></item>
    <item android:drawable="@drawable/down_icon"></item>
</selector>

3) Then create group_header.xml layout with following details and inflate this layout in getGroupView() method of ExpandableListAdapter.java:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp">

    <TextView
        android:id="@+id/tvHeader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:textColor="@color/white"
        android:layout_centerVertical="true"
        android:textSize="16sp"/>

    <ImageView
        android:id="@+id/ivGroupIndicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/group_indicator"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"/>
</RelativeLayout>

3) In getGroupView() method of your ExpandableListAdapter.java class, just set the following:

ivGroupIndicator.setSelected(isExpanded);

With this approach, your down_icon and up_icon will work properly. Hope this helps.


I don't know a way to do that from XML but i'll tell you a way to do so dynamically in your adapter.

First you have to remove group indicator from your xml

 <ExpandableListView [...] 
    android:groupIndicator="@null" />

Then in your layout of the parent add an imageview in the right position of your layout.

Then in your custom adapter do the following

public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
  ...

    if (isExpanded) {
        groupHolder.img.setImageResource(R.drawable.group_down);
    } else {
        groupHolder.img.setImageResource(R.drawable.group_up);
    }
  ...

}