I am trying to use a custom icon for group expand and collapse state of an ExpandableListView. But this doesn't seem to work. The icons doesn't get changed even when the Output messages are working sequentially.
explistView.setOnGroupClickListener(new OnGroupClickListener()
{
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id)
{
groupIndicator = (ImageView) findViewById(R.id.group_indicator);
if (parent.isGroupExpanded(groupPosition))
{
System.out.println("1");
parent.collapseGroup(groupPosition);
System.out.println("2");
groupIndicator.setImageResource(R.drawable.expand_icon_35x35);
System.out.println("3");
adapter.notifyDataSetChanged();
}
else
{
System.out.println("4");
parent.expandGroup(groupPosition);
System.out.println("5");
groupIndicator.setImageResource(R.drawable.collapse_icon_35x35);
System.out.println("6");
adapter.notifyDataSetChanged();
}
return true;
}
});
You can refer to this answer
You can change the icons by using following:-
<ExpandableListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:groupIndicator="@drawable/settings_selector"
/>
and Setting selector is:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/up_arrow" android:state_empty="true"/>
<item android:drawable="@drawable/down_arrow" android:state_expanded="true"/>
</selector>
In my case, android:state_empty="true" is not working. So, I changed it to android:state_expanded="false" .
<ExpandableListView
android:id="@+id/expl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:groupIndicator="@drawable/settings_selector"/>
And
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/plus_arrow" android:state_expanded="true"/>
<item android:drawable="@drawable/minus_arrow" android:state_expanded="false"/>
</selector>
I hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.