Android APIs
public abstract class

CursorTreeAdapter

extends BaseExpandableListAdapter
implements Filterable
java.lang.Object
   ↳ android.widget.BaseExpandableListAdapter
     ↳ android.widget.CursorTreeAdapter
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

An adapter that exposes data from a series of Cursors to an ExpandableListView widget. The top-level Cursor (that is given in the constructor) exposes the groups, while subsequent Cursors returned from getChildrenCursor(Cursor) expose children within a particular group. The Cursors must include a column named "_id" or this class will not work.

Summary

Public Constructors
CursorTreeAdapter(Cursor cursor, Context context)
Constructor.
CursorTreeAdapter(Cursor cursor, Context context, boolean autoRequery)
Constructor.
Public Methods
void changeCursor(Cursor cursor)
String convertToString(Cursor cursor)
Cursor getChild(int groupPosition, int childPosition)
long getChildId(int groupPosition, int childPosition)
View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
int getChildrenCount(int groupPosition)
Cursor getCursor()
Filter getFilter()

Returns a filter that can be used to constrain data with a filtering pattern.

FilterQueryProvider getFilterQueryProvider()
Cursor getGroup(int groupPosition)
int getGroupCount()
long getGroupId(int groupPosition)
View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
boolean hasStableIds()
boolean isChildSelectable(int groupPosition, int childPosition)
void notifyDataSetChanged(boolean releaseCursors)
Notifies a data set change, but with the option of not releasing any cached cursors.
void notifyDataSetChanged()
void notifyDataSetInvalidated()
void onGroupCollapsed(int groupPosition)
Called when a group is collapsed.
Cursor runQueryOnBackgroundThread(CharSequence constraint)
void setChildrenCursor(int groupPosition, Cursor childrenCursor)
Sets the children Cursor for a particular group.
void setFilterQueryProvider(FilterQueryProvider filterQueryProvider)
void setGroupCursor(Cursor cursor)
Sets the group Cursor.
Protected Methods
abstract void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild)
Bind an existing view to the child data pointed to by cursor
abstract void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded)
Bind an existing view to the group data pointed to by cursor.
abstract Cursor getChildrenCursor(Cursor groupCursor)
Gets the Cursor for the children at the given group.
abstract View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent)
Makes a new child view to hold the data pointed to by cursor.
abstract View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent)
Makes a new group view to hold the group data pointed to by cursor.
[Expand]
Inherited Methods
From class android.widget.BaseExpandableListAdapter
From class java.lang.Object
From interface android.widget.ExpandableListAdapter
From interface android.widget.Filterable
From interface android.widget.HeterogeneousExpandableList

Public Constructors

public CursorTreeAdapter (Cursor cursor, Context context)

Added in API level 1

Constructor. The adapter will call requery() on the cursor whenever it changes so that the most recent data is always displayed.

Parameters
cursor The cursor from which to get the data for the groups.

public CursorTreeAdapter (Cursor cursor, Context context, boolean autoRequery)

Added in API level 1

Constructor.

Parameters
cursor The cursor from which to get the data for the groups.
context The context
autoRequery If true the adapter will call requery() on the cursor whenever it changes so the most recent data is always displayed.

Public Methods

public void changeCursor (Cursor cursor)

Added in API level 1

public String convertToString (Cursor cursor)

Added in API level 1

public Cursor getChild (int groupPosition, int childPosition)

Added in API level 1

public long getChildId (int groupPosition, int childPosition)

Added in API level 1

public View getChildView (int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)

Added in API level 1

public int getChildrenCount (int groupPosition)

Added in API level 1

public Cursor getCursor ()

Added in API level 1

See Also

public Filter getFilter ()

Added in API level 1

Returns a filter that can be used to constrain data with a filtering pattern.

This method is usually implemented by Adapter classes.

Returns
  • a filter used to constrain data

public FilterQueryProvider getFilterQueryProvider ()

Added in API level 1

public Cursor getGroup (int groupPosition)

Added in API level 1

public int getGroupCount ()

Added in API level 1

public long getGroupId (int groupPosition)

Added in API level 1

public View getGroupView (int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)

Added in API level 1

public boolean hasStableIds ()

Added in API level 1

public boolean isChildSelectable (int groupPosition, int childPosition)

Added in API level 1

public void notifyDataSetChanged (boolean releaseCursors)

Added in API level 1

Notifies a data set change, but with the option of not releasing any cached cursors.

Parameters
releaseCursors Whether to release and deactivate any cached cursors.

public void notifyDataSetChanged ()

Added in API level 1

public void notifyDataSetInvalidated ()

Added in API level 1

public void onGroupCollapsed (int groupPosition)

Added in API level 1

Called when a group is collapsed.

Parameters
groupPosition The group being collapsed.

public Cursor runQueryOnBackgroundThread (CharSequence constraint)

Added in API level 1

public void setChildrenCursor (int groupPosition, Cursor childrenCursor)

Added in API level 1

Sets the children Cursor for a particular group. If there is an existing cursor it will be closed.

This is useful when asynchronously querying to prevent blocking the UI.

Parameters
groupPosition The group whose children are being set via this Cursor.
childrenCursor The Cursor that contains the children of the group.

public void setFilterQueryProvider (FilterQueryProvider filterQueryProvider)

Added in API level 1

public void setGroupCursor (Cursor cursor)

Added in API level 1

Sets the group Cursor.

Parameters
cursor The Cursor to set for the group. If there is an existing cursor it will be closed.

Protected Methods

protected abstract void bindChildView (View view, Context context, Cursor cursor, boolean isLastChild)

Added in API level 1

Bind an existing view to the child data pointed to by cursor

Parameters
view Existing view, returned earlier by newChildView
context Interface to application's global information
cursor The cursor from which to get the data. The cursor is already moved to the correct position.
isLastChild Whether the child is the last child within its group.

protected abstract void bindGroupView (View view, Context context, Cursor cursor, boolean isExpanded)

Added in API level 1

Bind an existing view to the group data pointed to by cursor.

Parameters
view Existing view, returned earlier by newGroupView.
context Interface to application's global information
cursor The cursor from which to get the data. The cursor is already moved to the correct position.
isExpanded Whether the group is expanded.

protected abstract Cursor getChildrenCursor (Cursor groupCursor)

Added in API level 1

Gets the Cursor for the children at the given group. Subclasses must implement this method to return the children data for a particular group.

If you want to asynchronously query a provider to prevent blocking the UI, it is possible to return null and at a later time call setChildrenCursor(int, Cursor).

It is your responsibility to manage this Cursor through the Activity lifecycle. It is a good idea to use managedQuery(Uri, String[], String, String[], String) which will handle this for you. In some situations, the adapter will deactivate the Cursor on its own, but this will not always be the case, so please ensure the Cursor is properly managed.

Parameters
groupCursor The cursor pointing to the group whose children cursor should be returned
Returns
  • The cursor for the children of a particular group, or null.

protected abstract View newChildView (Context context, Cursor cursor, boolean isLastChild, ViewGroup parent)

Added in API level 1

Makes a new child view to hold the data pointed to by cursor.

Parameters
context Interface to application's global information
cursor The cursor from which to get the data. The cursor is already moved to the correct position.
isLastChild Whether the child is the last child within its group.
parent The parent to which the new view is attached to
Returns
  • the newly created view.

protected abstract View newGroupView (Context context, Cursor cursor, boolean isExpanded, ViewGroup parent)

Added in API level 1

Makes a new group view to hold the group data pointed to by cursor.

Parameters
context Interface to application's global information
cursor The group cursor from which to get the data. The cursor is already moved to the correct position.
isExpanded Whether the group is expanded.
parent The parent to which the new view is attached to
Returns
  • The newly created view.