Android
android.widget
public abstract class

android.widget.CursorAdapter

java.lang.Object
android.widget.BaseAdapter ListAdapter SpinnerAdapter
android.widget.CursorAdapter Filterable

Adapter that exposes data from a Cursor to a ListView widget. The Cursor must include a column named "_id" or this class will not work.

Known Direct Subclasses
Known Indirect Subclasses

Summary

Constants inherited from interface android.widget.Adapter

Fields

protected      boolean  mAutoRequery   
protected      CursorAdapter.ChangeObserver  mChangeObserver   
protected      Context  mContext   
protected      Cursor  mCursor   
protected      CursorFilter  mCursorFilter   
protected      DataSetObserver  mDataSetObserver   
protected      boolean  mDataValid   
protected      FilterQueryProvider  mFilterQueryProvider   
protected      int  mRowIDColumn   

Public Constructors

            CursorAdapter(Context context, Cursor c)
Constructor.
            CursorAdapter(Context context, Cursor c, boolean autoRequery)
Constructor

Public Methods

abstract          void  bindView(View view, Context context, Cursor cursor)
Bind an existing view to the data pointed to by cursor
          void  changeCursor(Cursor cursor)
Change the underlying cursor to a new cursor.
          CharSequence  convertToString(Cursor cursor)

Converts the cursor into a CharSequence.

    final      int  getCount()
          Cursor  getCursor()
Returns the cursor.
          View  getDropDownView(int position, View convertView, ViewGroup parent)

Get a View that displays in the drop down popup the data at the specified position in the data set.

          Filter  getFilter()

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

          FilterQueryProvider  getFilterQueryProvider()
Returns the query filter provider used for filtering.
    final      Object  getItem(int position)
    final      long  getItemId(int position)
          View  getView(int position, View convertView, ViewGroup parent)
          boolean  hasStableIds()
Indicated whether the item ids are stable across changes to the underlying data.
          View  newDropDownView(Context context, Cursor cursor, ViewGroup parent)
Makes a new drop down view to hold the data pointed to by cursor.
abstract          View  newView(Context context, Cursor cursor, ViewGroup parent)
Makes a new view to hold the data pointed to by cursor.
          Cursor  runQueryOnBackgroundThread(CharSequence constraint)
Runs a query with the specified constraint.
          void  setFilterQueryProvider(FilterQueryProvider filterQueryProvider)
Sets the query filter provider used to filter the current Cursor.

Protected Methods

          void  init(Context context, Cursor c, boolean autoRequery)
Methods inherited from class android.widget.BaseAdapter
Methods inherited from class java.lang.Object
Methods inherited from interface android.widget.Adapter
Methods inherited from interface android.widget.Filterable
Methods inherited from interface android.widget.ListAdapter
Methods inherited from interface android.widget.SpinnerAdapter

Details

Fields

protected boolean mAutoRequery

protected CursorAdapter.ChangeObserver mChangeObserver

protected Context mContext

protected Cursor mCursor

protected CursorFilter mCursorFilter

protected DataSetObserver mDataSetObserver

protected boolean mDataValid

protected FilterQueryProvider mFilterQueryProvider

protected int mRowIDColumn

Public Constructors

public CursorAdapter(Context context, Cursor c)

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

Parameters

context The context
c The cursor from which to get the data.

public CursorAdapter(Context context, Cursor c, boolean autoRequery)

Constructor

Parameters

context The context
c The cursor from which to get the data.
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 abstract void bindView(View view, Context context, Cursor cursor)

Bind an existing view to the data pointed to by cursor

Parameters

view Existing view, returned earlier by newView
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.

public void changeCursor(Cursor cursor)

Change the underlying cursor to a new cursor. If there is an existing cursor it will be closed.

Parameters

cursor the new cursor to be used

public CharSequence convertToString(Cursor cursor)

Converts the cursor into a CharSequence. Subclasses should override this method to convert their results. The default implementation returns an empty String for null values or the default String representation of the value.

Parameters

cursor the cursor to convert to a CharSequence

Returns

  • a CharSequence representing the value

public final int getCount()

See Also

public Cursor getCursor()

Returns the cursor.

Returns

  • the cursor.

public View getDropDownView(int position, View convertView, ViewGroup parent)

Get a View that displays in the drop down popup the data at the specified position in the data set.

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.

public FilterQueryProvider getFilterQueryProvider()

Returns the query filter provider used for filtering. When the provider is null, no filtering occurs.

Returns

  • the current filter query provider or null if it does not exist

public final Object getItem(int position)

See Also

public final long getItemId(int position)

See Also

public View getView(int position, View convertView, ViewGroup parent)

public boolean hasStableIds()

Indicated whether the item ids are stable across changes to the underlying data.

public View newDropDownView(Context context, Cursor cursor, ViewGroup parent)

Makes a new drop down 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.
parent The parent to which the new view is attached to

Returns

  • the newly created view.

public abstract View newView(Context context, Cursor cursor, ViewGroup parent)

Makes a new 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.
parent The parent to which the new view is attached to

Returns

  • the newly created view.

public Cursor runQueryOnBackgroundThread(CharSequence constraint)

Runs a query with the specified constraint. This query is requested by the filter attached to this adapter. The query is provided by a FilterQueryProvider. If no provider is specified, the current cursor is not filtered and returned. After this method returns the resulting cursor is passed to changeCursor(Cursor) and the previous cursor is closed. This method is always executed on a background thread, not on the application's main thread (or UI thread.) Contract: when constraint is null or empty, the original results, prior to any filtering, must be returned.

Parameters

constraint the constraint with which the query must be filtered

Returns

  • a Cursor representing the results of the new query

public void setFilterQueryProvider(FilterQueryProvider filterQueryProvider)

Sets the query filter provider used to filter the current Cursor. The provider's runQuery(CharSequence) method is invoked when filtering is requested by a client of this adapter.

Parameters

filterQueryProvider the filter query provider or null to remove it

Protected Methods

protected void init(Context context, Cursor c, boolean autoRequery)

Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56