I\'m creating an ExpandableListView
with data from a database. For that, I\'m using a CursorTreeAdapter
and I populate it with a Cursor
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 );
}
}
Why not leave the groups with no children out?
Change your query to give you only groups that will have children.
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);
}
}