简体   繁体   English

ExpandableListView中的自定义组展开图标

[英]Custom group expanding icon in ExpandableListView

在此输入图像描述

I am trying to use a custom icon for group expand and collapse state of an ExpandableListView. 我正在尝试使用自定义图标进行扩展和折叠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. 在我的情况下, android:state_empty =“true”不起作用。 So, I changed it to android:state_expanded="false" . 所以,我把它改成了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. 我希望它有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM