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.
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>
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.
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With