Skip to content Skip to sidebar Skip to footer

Expandablelistview Is Showing Indicator For Groups With No Child

I'm creating an ExpandableListView with data from a database. For that, I'm using a CursorTreeAdapter and I populate it with a Cursor object which contains the data I retrieve from

Solution 1:

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:

@OverrideprotectedvoidbindGroupView(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);
    }
}

Solution 2:

In your adapter class use:

public View getGroupView(int groupPosition, boolean isExpanded, View convertView,ViewGroup parent) 
{
    if (getChildrenCount(groupPosition) == 0 ) {
           indicator.setVisibility( View.INVISIBLE );
    } 
    else {
           indicator.setVisibility( View.VISIBLE );
           indicator.setImageResource( isExpanded ? R.drawable.group_expanded : R.drawable.group_closed );
    }
}

Solution 3:

Why not leave the groups with no children out?

Change your query to give you only groups that will have children.

Post a Comment for "Expandablelistview Is Showing Indicator For Groups With No Child"