ExpandableListView 中的自定义组扩展图标

Ver*_*ert 5 android expandablelistview

在此处输入图片说明

我正在尝试将自定义图标用于 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;
        }
    });
Run Code Online (Sandbox Code Playgroud)

Ani*_*rma 0

你可以参考这个答案

您可以使用以下方法更改图标:-

<ExpandableListView android:id="@+id/list"
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"
       android:layout_marginTop="10dp"
       android:groupIndicator="@drawable/settings_selector"
   />
Run Code Online (Sandbox Code Playgroud)

设置选择器是:

<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>
Run Code Online (Sandbox Code Playgroud)