SimpleCursorTreeAdapter


public abstract class SimpleCursorTreeAdapter
extends ResourceCursorTreeAdapter

java.lang.Object
   ↳ android.widget.BaseExpandableListAdapter
     ↳ android.widget.CursorTreeAdapter
       ↳ android.widget.ResourceCursorTreeAdapter
         ↳ android.widget.SimpleCursorTreeAdapter


An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. You can specify which columns you want, which views you want to display the columns, and the XML file that defines the appearance of these views. Separate XML files for child and groups are possible. Binding occurs in two phases. First, if a SimpleCursorTreeAdapter.ViewBinder is available, ViewBinder.setViewValue(android.view.View, android.database.Cursor, int) is invoked. If the returned value is true, binding has occurred. If the returned value is false and the view to bind is a TextView, setViewText(android.widget.TextView, java.lang.String) is invoked. If the returned value is false and the view to bind is an ImageView, setViewImage(android.widget.ImageView, java.lang.String) is invoked. If no appropriate binding can be found, an IllegalStateException is thrown.

Summary

Nested classes

interface SimpleCursorTreeAdapter.ViewBinder

This class can be used by external clients of SimpleCursorTreeAdapter to bind values from the Cursor to views. 

Public constructors

SimpleCursorTreeAdapter(Context context, Cursor cursor, int collapsedGroupLayout, int expandedGroupLayout, String[] groupFrom, int[] groupTo, int childLayout, int lastChildLayout, String[] childFrom, int[] childTo)

Constructor.

SimpleCursorTreeAdapter(Context context, Cursor cursor, int collapsedGroupLayout, int expandedGroupLayout, String[] groupFrom, int[] groupTo, int childLayout, String[] childFrom, int[] childTo)

Constructor.

SimpleCursorTreeAdapter(Context context, Cursor cursor, int groupLayout, String[] groupFrom, int[] groupTo, int childLayout, String[] childFrom, int[] childTo)

Constructor.

Public methods

SimpleCursorTreeAdapter.ViewBinder getViewBinder()

Returns the ViewBinder used to bind data to views.

void setViewBinder(SimpleCursorTreeAdapter.ViewBinder viewBinder)

Sets the binder used to bind data to views.

void setViewText(TextView v, String text)

Called by bindView() to set the text for a TextView but only if there is no existing ViewBinder or if the existing ViewBinder cannot handle binding to a TextView.

Protected methods

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

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

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

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

void setViewImage(ImageView v, String value)

Called by bindView() to set the image for an ImageView.

Inherited methods

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

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

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

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

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.

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)
abstract Cursor getChildrenCursor(Cursor groupCursor)

Gets the Cursor for the children at the given group.

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)
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.

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.

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 Filter getFilter()

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

    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) .

    Public constructors

    SimpleCursorTreeAdapter

    Added in API level 1
    public SimpleCursorTreeAdapter (Context context, 
                    Cursor cursor, 
                    int collapsedGroupLayout, 
                    int expandedGroupLayout, 
                    String[] groupFrom, 
                    int[] groupTo, 
                    int childLayout, 
                    int lastChildLayout, 
                    String[] childFrom, 
                    int[] childTo)

    Constructor.

    Parameters
    context Context: The context where the ExpandableListView associated with this SimpleCursorTreeAdapter is running

    cursor Cursor: The database cursor

    collapsedGroupLayout int: The resource identifier of a layout file that defines the views for a collapsed group. The layout file should include at least those named views defined in groupTo.

    expandedGroupLayout int: The resource identifier of a layout file that defines the views for an expanded group. The layout file should include at least those named views defined in groupTo.

    groupFrom String: A list of column names that will be used to display the data for a group.

    groupTo int: The group views (from the group layouts) that should display column in the "from" parameter. These should all be TextViews or ImageViews. The first N views in this list are given the values of the first N columns in the from parameter.

    childLayout int: The resource identifier of a layout file that defines the views for a child (except the last). The layout file should include at least those named views defined in childTo.

    lastChildLayout int: The resource identifier of a layout file that defines the views for the last child within a group. The layout file should include at least those named views defined in childTo.

    childFrom String: A list of column names that will be used to display the data for a child.

    childTo int: The child views (from the child layouts) that should display column in the "from" parameter. These should all be TextViews or ImageViews. The first N views in this list are given the values of the first N columns in the from parameter.

    SimpleCursorTreeAdapter

    Added in API level 1
    public SimpleCursorTreeAdapter (Context context, 
                    Cursor cursor, 
                    int collapsedGroupLayout, 
                    int expandedGroupLayout, 
                    String[] groupFrom, 
                    int[] groupTo, 
                    int childLayout, 
                    String[] childFrom, 
                    int[] childTo)

    Constructor.

    Parameters
    context Context: The context where the ExpandableListView associated with this SimpleCursorTreeAdapter is running

    cursor Cursor: The database cursor

    collapsedGroupLayout int: The resource identifier of a layout file that defines the views for a collapsed group. The layout file should include at least those named views defined in groupTo.

    expandedGroupLayout int: The resource identifier of a layout file that defines the views for an expanded group. The layout file should include at least those named views defined in groupTo.

    groupFrom String: A list of column names that will be used to display the data for a group.

    groupTo int: The group views (from the group layouts) that should display column in the "from" parameter. These should all be TextViews or ImageViews. The first N views in this list are given the values of the first N columns in the from parameter.

    childLayout int: The resource identifier of a layout file that defines the views for a child. The layout file should include at least those named views defined in childTo.

    childFrom String: A list of column names that will be used to display the data for a child.

    childTo int: The child views (from the child layouts) that should display column in the "from" parameter. These should all be TextViews or ImageViews. The first N views in this list are given the values of the first N columns in the from parameter.

    SimpleCursorTreeAdapter

    Added in API level 1
    public SimpleCursorTreeAdapter (Context context, 
                    Cursor cursor, 
                    int groupLayout, 
                    String[] groupFrom, 
                    int[] groupTo, 
                    int childLayout, 
                    String[] childFrom, 
                    int[] childTo)

    Constructor.

    Parameters
    context Context: The context where the ExpandableListView associated with this SimpleCursorTreeAdapter is running

    cursor Cursor: The database cursor

    groupLayout int: The resource identifier of a layout file that defines the views for a group. The layout file should include at least those named views defined in groupTo.

    groupFrom String: A list of column names that will be used to display the data for a group.

    groupTo int: The group views (from the group layouts) that should display column in the "from" parameter. These should all be TextViews or ImageViews. The first N views in this list are given the values of the first N columns in the from parameter.

    childLayout int: The resource identifier of a layout file that defines the views for a child. The layout file should include at least those named views defined in childTo.

    childFrom String: A list of column names that will be used to display the data for a child.

    childTo int: The child views (from the child layouts) that should display column in the "from" parameter. These should all be TextViews or ImageViews. The first N views in this list are given the values of the first N columns in the from parameter.

    Public methods

    getViewBinder

    Added in API level 5
    public SimpleCursorTreeAdapter.ViewBinder getViewBinder ()

    Returns the ViewBinder used to bind data to views.

    Returns
    SimpleCursorTreeAdapter.ViewBinder a ViewBinder or null if the binder does not exist

    setViewBinder

    Added in API level 5
    public void setViewBinder (SimpleCursorTreeAdapter.ViewBinder viewBinder)

    Sets the binder used to bind data to views.

    Parameters
    viewBinder SimpleCursorTreeAdapter.ViewBinder: the binder used to bind data to views, can be null to remove the existing binder

    See also:

    setViewText

    Added in API level 5
    public void setViewText (TextView v, 
                    String text)

    Called by bindView() to set the text for a TextView but only if there is no existing ViewBinder or if the existing ViewBinder cannot handle binding to a TextView. Intended to be overridden by Adapters that need to filter strings retrieved from the database.

    Parameters
    v TextView: TextView to receive text

    text String: the text to be set for the TextView

    Protected methods

    bindChildView

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

    setViewImage

    Added in API level 1
    protected void setViewImage (ImageView v, 
                    String value)

    Called by bindView() to set the image for an ImageView. By default, the value will be treated as a Uri. Intended to be overridden by Adapters that need to filter strings retrieved from the database.

    Parameters
    v ImageView: ImageView to receive an image

    value String: the value retrieved from the cursor