我正在尝试使用自定义图标进行ExpandableListView的组展开和折叠状态。但这似乎不起作用。即使输出消息按顺序工作,图标也不会更改。
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;
}
});
答案 0 :(得分:0)
您可以参考此answer
您可以使用以下方法更改图标: -
<ExpandableListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:groupIndicator="@drawable/settings_selector"
/>
和设置选择器是:
<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>
答案 1 :(得分:0)
就我而言, android:state_empty =“true”无效。 所以,我把它改为 android:state_expanded =“false”。
<ExpandableListView
android:id="@+id/expl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:groupIndicator="@drawable/settings_selector"/>
和
<?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>
我希望它有所帮助。