Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change expandable indicator in ExpandableListView

Trying to create an ExpandableListView. The initial view with the groups shows up fine. However, when I click the list item, my arrow does not change. See the images below.

enter image description here

How can I change the arrow's direction?

The layout XML:

  <ExpandableListView         android:id="@+id/expandable_list"         android:layout_width="fill_parent"         android:layout_height="match_parent"                     android:divider="@null"         android:background="#ffffff"         android:groupIndicator="@drawable/settings_selector"         android:transcriptMode="alwaysScroll" /> 

settings_selector.xml:

 <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" >  <selector xmlns:android="http://schemas.android.com/apk/res/android" >     <item         android:drawable="@drawable/arrow_down"         android:state_empty="true"/>     <item         android:drawable="@drawable/arrow_right"         android:state_expanded="true"/> </selector>  </animation-list> 
like image 672
NagarjunaReddy Avatar asked Mar 19 '13 13:03

NagarjunaReddy


People also ask

What is Expandable list view?

Android ExpandableListView is a view that shows items in a vertically scrolling two-level list. It differs from a ListView by allowing two levels which are groups that can be easily expanded and collapsed by touching to view and their respective children items.


2 Answers

expandable listview

 <ExpandableListView     android:id="@+id/expandable_list"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:groupIndicator="@drawable/group_indicator"     android:transcriptMode="alwaysScroll" /> 

setindicator here iam useing setindicator code like this this working nice

 DisplayMetrics metrics = new DisplayMetrics();     getWindowManager().getDefaultDisplay().getMetrics(metrics);     int width = metrics.widthPixels;    mExpandableList = (ExpandableListView)findViewById(R.id.expandable_list);  mExpandableList.setIndicatorBounds(width - GetPixelFromDips(50), width - GetPixelFromDips(10));       public int GetPixelFromDips(float pixels) {     // Get the screen's density scale      final float scale = getResources().getDisplayMetrics().density;     // Convert the dps to pixels, based on density scale     return (int) (pixels * scale + 0.5f); } 

res/drawable/group_indicator

  <?xml version="1.0" encoding="utf-8"?>       <selector xmlns:android="http://schemas.android.com/apk/res/android">                        <item android:drawable="@drawable/arrow_right" android:state_empty="true">  </item>                        <item android:drawable="@drawable/arrow_down" android:state_expanded="true"></item>                            <item android:drawable="@drawable/arrow_right"></item>      </selector> 
like image 151
NagarjunaReddy Avatar answered Oct 19 '22 07:10

NagarjunaReddy


Try that for your settings_selector.xml:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" >      <item         android:drawable="@drawable/arrow_right"         android:state_expanded="true" />      <item         android:drawable="@drawable/arrow_down" />  </selector> 
like image 40
Benoit Duffez Avatar answered Oct 19 '22 05:10

Benoit Duffez