CursorTreeAdapter


public abstract class CursorTreeAdapter
extends BaseExpandableListAdapter implements Filterable

java.lang.Object
   ↳ android.widget.BaseExpandableListAdapter
     ↳ android.widget.CursorTreeAdapter
ResourceCursorTreeAdapter A fairly simple ExpandableListAdapter that creates views defined in an XML file. 
SimpleCursorTreeAdapter An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. 


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(android.database.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()
void notifyDataSetChanged(boolean releaseCursors)

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

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.

Inherited methods

boolean areAllItemsEnabled()
int getChildType(int groupPosition, int childPosition)

Get the type of child View that will be created by ExpandableListAdapter.getChildView(int, int, boolean, View, ViewGroup) for the specified child item.

int getChildTypeCount()

Returns the number of types of child Views that will be created by ExpandableListAdapter.getChildView(int, int, boolean, View, ViewGroup) .

long getCombinedChildId(long groupId, long childId)

Override this method if you foresee a clash in IDs based on this scheme:

Base implementation returns a long:

  • bit 0: Whether this ID points to a child (unset) or group (set), so for this method this bit will be 1.

  • long getCombinedGroupId(long groupId)

    Override this method if you foresee a clash in IDs based on this scheme:

    Base implementation returns a long:

  • bit 0: Whether this ID points to a child (unset) or group (set), so for this method this bit will be 0.

  • int getGroupType(int groupPosition)

    Get the type of group View that will be created by ExpandableListAdapter.getGroupView(int, boolean, View, ViewGroup) .

    int getGroupTypeCount()

    Returns the number of types of group Views that will be created by ExpandableListAdapter.getGroupView(int, boolean, View, ViewGroup) .

    boolean isEmpty()

    void notifyDataSetChanged()
    void notifyDataSetInvalidated()
    void onGroupCollapsed(int groupPosition)

    Called when a group is collapsed.

    void onGroupExpanded(int groupPosition)

    Called when a group is expanded.

    void registerDataSetObserver(DataSetObserver observer)
    void unregisterDataSetObserver(DataSetObserver observer)
    Object clone()

    Creates and returns a copy of this object.

    boolean equals(Object obj)

    Indicates whether some other object is "equal to" this one.

    void finalize()

    Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

    final Class<?> getClass()

    Returns the runtime class of this Object.

    int hashCode()

    Returns a hash code value for the object.

    final void notify()

    Wakes up a single thread that is waiting on this object's monitor.

    final void notifyAll()

    Wakes up all threads that are waiting on this object's monitor.

    String toString()

    Returns a string representation of the object.

    final void wait(long timeoutMillis, int nanos)

    Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

    final void wait(long timeoutMillis)

    Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

    final void wait()

    Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

    abstract boolean areAllItemsEnabled()
    abstract Object getChild(int groupPosition, int childPosition)

    Gets the data associated with the given child within the given group.

    abstract long getChildId(int groupPosition, int childPosition)

    Gets the ID for the given child within the given group.

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

    Gets a View that displays the data for the given child within the given group.

    abstract int getChildrenCount(int groupPosition)

    Gets the number of children in a specified group.

    abstract long getCombinedChildId(long groupId, long childId)

    Gets an ID for a child that is unique across any item (either group or child) that is in this list.

    abstract long getCombinedGroupId(long groupId)

    Gets an ID for a group that is unique across any item (either group or child) that is in this list.

    abstract Object getGroup(int groupPosition)

    Gets the data associated with the given group.

    abstract int getGroupCount()

    Gets the number of groups.

    abstract long getGroupId(int groupPosition)

    Gets the ID for the group at the given position.

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

    Gets a View that displays the given group.

    abstract boolean hasStableIds()

    Indicates whether the child and group IDs are stable across changes to the underlying data.

    abstract boolean isChildSelectable(int groupPosition, int childPosition)

    Whether the child at the specified position is selectable.

    abstract boolean isEmpty()
    abstract void onGroupCollapsed(int groupPosition)

    Called when a group is collapsed.

    abstract void onGroupExpanded(int groupPosition)

    Called when a group is expanded.

    abstract void registerDataSetObserver(DataSetObserver observer)
    abstract void unregisterDataSetObserver(DataSetObserver observer)
    abstract int getChildType(int groupPosition, int childPosition)

    Get the type of child View that will be created by ExpandableListAdapter.getChildView(int, int, boolean, View, ViewGroup) for the specified child item.

    abstract int getChildTypeCount()

    Returns the number of types of child Views that will be created by ExpandableListAdapter.getChildView(int, int, boolean, View, ViewGroup) .

    abstract int getGroupType(int groupPosition)

    Get the type of group View that will be created by ExpandableListAdapter.getGroupView(int, boolean, View, ViewGroup) .

    abstract int getGroupTypeCount()

    Returns the number of types of group Views that will be created by ExpandableListAdapter.getGroupView(int, boolean, View, ViewGroup) .

    abstract Filter getFilter()

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

    Public constructors

    CursorTreeAdapter

    Added in API level 1
    public CursorTreeAdapter (Cursor cursor, 
                    Context context)

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

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

    context Context

    CursorTreeAdapter

    Added in API level 1
    public CursorTreeAdapter (Cursor cursor, 
                    Context context, 
                    boolean autoRequery)

    Constructor.

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

    context Context: The context

    autoRequery boolean: If true the adapter will call Cursor.requery() on the cursor whenever it changes so the most recent data is always displayed.

    Public methods

    changeCursor

    Added in API level 1
    public void changeCursor (Cursor cursor)

    Parameters
    cursor Cursor

    convertToString

    Added in API level 1
    public String convertToString (Cursor cursor)

    Parameters
    cursor Cursor

    Returns
    String

    getChild

    Added in API level 1
    public Cursor getChild (int groupPosition, 
                    int childPosition)

    Parameters
    groupPosition int

    childPosition int

    Returns
    Cursor

    getChildId

    Added in API level 1
    public long getChildId (int groupPosition, 
                    int childPosition)

    Parameters
    groupPosition int

    childPosition int

    Returns
    long

    getChildView

    Added in API level 1
    public View getChildView (int groupPosition, 
                    int childPosition, 
                    boolean isLastChild, 
                    View convertView, 
                    ViewGroup parent)

    Parameters
    groupPosition int

    childPosition int

    isLastChild boolean

    convertView View

    parent ViewGroup

    Returns
    View

    getChildrenCount

    Added in API level 1
    public int getChildrenCount (int groupPosition)

    Parameters
    groupPosition int

    Returns
    int

    getCursor

    Added in API level 1
    public Cursor getCursor ()

    Returns
    Cursor

    getFilter

    Added in API level 1
    public Filter getFilter ()

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

    This method is usually implemented by Adapter classes.

    Returns
    Filter a filter used to constrain data

    getFilterQueryProvider

    Added in API level 1
    public FilterQueryProvider getFilterQueryProvider ()

    getGroup

    Added in API level 1
    public Cursor getGroup (int groupPosition)

    Parameters
    groupPosition int

    Returns
    Cursor

    getGroupCount

    Added in API level 1
    public int getGroupCount ()

    Returns
    int

    getGroupId

    Added in API level 1
    public long getGroupId (int groupPosition)

    Parameters
    groupPosition int

    Returns
    long

    getGroupView

    Added in API level 1
    public View getGroupView (int groupPosition, 
                    boolean isExpanded, 
                    View convertView, 
                    ViewGroup parent)

    Parameters
    groupPosition int

    isExpanded boolean

    convertView View

    parent ViewGroup

    Returns
    View

    hasStableIds

    Added in API level 1
    public boolean hasStableIds ()

    Returns
    boolean

    isChildSelectable

    Added in API level 1
    public boolean isChildSelectable (int groupPosition, 
                    int childPosition)

    Parameters
    groupPosition int

    childPosition int

    Returns
    boolean

    notifyDataSetChanged

    Added in API level 1
    public void notifyDataSetChanged ()

    notifyDataSetChanged

    Added in API level 1
    public void notifyDataSetChanged (boolean releaseCursors)

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

    Parameters
    releaseCursors boolean: Whether to release and deactivate any cached cursors.

    notifyDataSetInvalidated

    Added in API level 1
    public void notifyDataSetInvalidated ()

    onGroupCollapsed

    Added in API level 1
    public void onGroupCollapsed (int groupPosition)

    Called when a group is collapsed.

    Parameters
    groupPosition int: The group being collapsed.

    runQueryOnBackgroundThread

    Added in API level 1
    public Cursor runQueryOnBackgroundThread (CharSequence constraint)

    Parameters
    constraint CharSequence

    Returns
    Cursor

    setChildrenCursor

    Added in API level 1
    public void setChildrenCursor (int groupPosition, 
                    Cursor childrenCursor)

    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 int: The group whose children are being set via this Cursor.

    childrenCursor Cursor: The Cursor that contains the children of the group.

    setFilterQueryProvider

    Added in API level 1
    public void setFilterQueryProvider (FilterQueryProvider filterQueryProvider)

    Parameters
    filterQueryProvider FilterQueryProvider

    setGroupCursor

    Added in API level 1
    public void setGroupCursor (Cursor cursor)

    Sets the group Cursor.

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

    Protected methods

    bindChildView

    Added in API level 1
    protected abstract void bindChildView (View view, 
                    Context context, 
                    Cursor cursor, 
                    boolean isLastChild)

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

    Parameters
    view View: Existing view, returned earlier by newChildView

    context Context: Interface to application's global information

    cursor Cursor: The cursor from which to get the data. The cursor is already moved to the correct position.

    isLastChild boolean: Whether the child is the last child within its group.

    bindGroupView

    Added in API level 1
    protected abstract void bindGroupView (View view, 
                    Context context, 
                    Cursor cursor, 
                    boolean isExpanded)

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

    Parameters
    view View: Existing view, returned earlier by newGroupView.

    context Context: Interface to application's global information

    cursor Cursor: The cursor from which to get the data. The cursor is already moved to the correct position.

    isExpanded boolean: Whether the group is expanded.

    getChildrenCursor

    Added in API level 1
    protected abstract Cursor getChildrenCursor (Cursor groupCursor)

    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, android.database.Cursor).

    It is your responsibility to manage this Cursor through the Activity lifecycle. It is a good idea to use Activity.managedQuery 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 Cursor: The cursor pointing to the group whose children cursor should be returned

    Returns
    Cursor The cursor for the children of a particular group, or null.

    newChildView

    Added in API level 1
    protected abstract View newChildView (Context context, 
                    Cursor cursor, 
                    boolean isLastChild, 
                    ViewGroup parent)

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

    Parameters
    context Context: Interface to application's global information

    cursor Cursor: The cursor from which to get the data. The cursor is already moved to the correct position.

    isLastChild boolean: Whether the child is the last child within its group.

    parent ViewGroup: The parent to which the new view is attached to

    Returns
    View the newly created view.

    newGroupView

    Added in API level 1
    protected 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.

    Parameters
    context Context: Interface to application's global information

    cursor Cursor: The group cursor from which to get the data. The cursor is already moved to the correct position.

    isExpanded boolean: Whether the group is expanded.

    parent ViewGroup: The parent to which the new view is attached to

    Returns
    View The newly created view.