ExpandableListView is showing indicator for groups with no child

前端 未结 3 608
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 02:12

I\'m creating an ExpandableListView with data from a database. For that, I\'m using a CursorTreeAdapter and I populate it with a Cursor

3条回答
  •  执笔经年
    2021-01-13 02:39

    In your xml add the folowing to ExpandableListView:

        android:groupIndicator="@android:color/transparent"
    

    Than each Group Item View in your Adapter needs its internal indicator. You can for example add a ImageView on the right side in your .xml.

    Then in the Adapter you do the following:

    @Override
    protected void bindGroupView(View view, Context paramContext, Cursor cursor, boolean paramBoolean) 
        ...
    
        if (getChildrenCount(groupPosition) > 0) {
            viewHolder.indicator.setVisibility(View.VISIBLE);
            viewHolder.indicator.setImageResource(
                    isExpanded ? R.drawable.indicator_expanded : R.drawable.indicator);
        } else {
            viewHolder.indicator.setVisibility(View.GONE);
        }
    }
    

提交回复
热议问题