簡體   English   中英

ExpandableListView中的自定義組展開圖標

[英]Custom group expanding icon in 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;
        }
    });

你可以參考這個答案

您可以使用以下內容更改圖標: -

<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>

在我的情況下, 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>

我希望它有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM