ExpandableListView - скрыть индикатор для групп без детей - PullRequest
101 голосов
/ 10 ноября 2010

В ExpandableListView есть ли способ скрыть индикатор группы для групп без детей?

Ответы [ 13 ]

0 голосов
/ 12 июня 2015

Вы пытались изменить атрибут ExpandableListView android:groupIndicator="@null"?

0 голосов
/ 16 октября 2014

Просто вы создаете новый макет XML с высотой = 0 для скрытого заголовка группы. Например, это 'group_list_item_empty.xml'

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"              
              android:layout_width="match_parent"
              android:layout_height="0dp">
</RelativeLayout>

Тогда ваш обычный макет заголовка группы - 'your_group_list_item_file.xml'

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="48dp"
              android:orientation="horizontal">
    ...your xml layout define...
</LinearLayout>

Наконец, вы просто обновляете метод getGroupView в своем классе адаптера:

public class MyExpandableListAdapter extends BaseExpandableListAdapter{   

    //Your code here ...

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup viewGroup) {
        if (Your condition to hide the group header){
            if (convertView == null || convertView instanceof LinearLayout) {
                LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
                convertView = mInflater.inflate(R.layout.group_list_item_empty, null);
            }           
            return convertView;
        }else{      
            if (convertView == null || convertView instanceof RelativeLayout) {
                LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
                convertView = mInflater.inflate(R.layout.your_group_list_item_file, null);              
            }   
            //Your code here ...
            return convertView;
        }
    }
}

ВАЖНО : корневой тег файлов макета (скрытый и обычный) должен быть разным (как в примере выше, LinearLayout и RelativeLayout)

0 голосов
/ 24 октября 2013

Используйте это, это прекрасно работает для меня.

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/group_indicator_expanded" android:state_empty="false" android:state_expanded="true"/>
<item android:drawable="@drawable/group_indicator" android:state_empty="true"/>
<item android:drawable="@drawable/group_indicator"/>

</selector>
...