added in version 22.1.0
belongs to Maven artifact com.android.support:cursoradapter:28.0.0-alpha1

CursorAdapter

public abstract class CursorAdapter
extends BaseAdapter implements Filterable

java.lang.Object
   ↳ android.widget.BaseAdapter
     ↳ android.support.v4.widget.CursorAdapter
Known Direct Subclasses
Known Indirect Subclasses


Static library support version of the framework's CursorAdapter. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.

Summary

Constants

int FLAG_AUTO_REQUERY

This constant was deprecated in API level 22.1.0. This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use LoaderManager with a CursorLoader.

int FLAG_REGISTER_CONTENT_OBSERVER

If set the adapter will register a content observer on the cursor and will call onContentChanged() when a notification comes in.

Inherited constants

From interface android.widget.Adapter

Public constructors

CursorAdapter(Context context, Cursor c)

This constructor was deprecated in API level 22.1.0. This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use LoaderManager with a CursorLoader.

CursorAdapter(Context context, Cursor c, boolean autoRequery)

Constructor that allows control over auto-requery.

CursorAdapter(Context context, Cursor c, int flags)

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

int getCount()
Cursor getCursor()

Returns the cursor.

View getDropDownView(int position, View convertView, ViewGroup parent)
Filter getFilter()
FilterQueryProvider getFilterQueryProvider()

Returns the query filter provider used for filtering.

Object getItem(int position)
long getItemId(int position)
View getView(int position, View convertView, ViewGroup parent)
boolean hasStableIds()
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.

Cursor swapCursor(Cursor newCursor)

Swap in a new Cursor, returning the old Cursor.

Protected methods

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

This method was deprecated in API level 22.1.0. Don't use this, use the normal constructor. This will be removed in the future.

void onContentChanged()

Called when the ContentObserver on the cursor receives a change notification.

Inherited methods

From class android.widget.BaseAdapter
From class java.lang.Object
From interface android.widget.ListAdapter
From interface android.widget.SpinnerAdapter
From interface android.widget.Filterable
From interface android.widget.Adapter

Constants

FLAG_AUTO_REQUERY

added in version 22.1.0
int FLAG_AUTO_REQUERY

This constant was deprecated in API level 22.1.0.
This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use LoaderManager with a CursorLoader.

If set the adapter will call requery() on the cursor whenever a content change notification is delivered. Implies FLAG_REGISTER_CONTENT_OBSERVER.

Constant Value: 1 (0x00000001)

FLAG_REGISTER_CONTENT_OBSERVER

added in version 22.1.0
int FLAG_REGISTER_CONTENT_OBSERVER

If set the adapter will register a content observer on the cursor and will call onContentChanged() when a notification comes in. Be careful when using this flag: you will need to unset the current Cursor from the adapter to avoid leaks due to its registered observers. This flag is not needed when using a CursorAdapter with a CursorLoader.

Constant Value: 2 (0x00000002)

Public constructors

CursorAdapter

added in version 22.1.0
CursorAdapter (Context context, 
                Cursor c)

This constructor was deprecated in API level 22.1.0.
This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use LoaderManager with a CursorLoader.

Constructor that always enables auto-requery.

Parameters
context Context: The context

c Cursor: The cursor from which to get the data.

CursorAdapter

added in version 22.1.0
CursorAdapter (Context context, 
                Cursor c, 
                boolean autoRequery)

Constructor that allows control over auto-requery. It is recommended you not use this, but instead CursorAdapter(Context, Cursor, int). When using this constructor, FLAG_REGISTER_CONTENT_OBSERVER will always be set.

Parameters
context Context: The context

c Cursor: The cursor from which to get the data.

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

CursorAdapter

added in version 22.1.0
CursorAdapter (Context context, 
                Cursor c, 
                int flags)

Recommended constructor.

Parameters
context Context: The context

c Cursor: The cursor from which to get the data.

flags int: Flags used to determine the behavior of the adapter; may be any combination of FLAG_AUTO_REQUERY and FLAG_REGISTER_CONTENT_OBSERVER.

Public methods

bindView

added in version 22.1.0
void bindView (View view, 
                Context context, 
                Cursor cursor)

Bind an existing view to the data pointed to by cursor

Parameters
view View: Existing view, returned earlier by newView

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.

changeCursor

added in version 22.1.0
void changeCursor (Cursor cursor)

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

Parameters
cursor Cursor: The new cursor to be used

convertToString

added in version 22.1.0
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 Cursor: the cursor to convert to a CharSequence

Returns
CharSequence a CharSequence representing the value

getCount

added in version 22.1.0
int getCount ()

Returns
int

See also:

getCursor

added in version 22.1.0
Cursor getCursor ()

Returns the cursor.

Returns
Cursor the cursor.

getDropDownView

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

Parameters
position int

convertView View

parent ViewGroup

Returns
View

getFilter

added in version 22.1.0
Filter getFilter ()

Returns
Filter

getFilterQueryProvider

added in version 22.1.0
FilterQueryProvider getFilterQueryProvider ()

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

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

getItem

added in version 22.1.0
Object getItem (int position)

Parameters
position int

Returns
Object

See also:

getItemId

added in version 22.1.0
long getItemId (int position)

Parameters
position int

Returns
long

See also:

getView

added in version 22.1.0
View getView (int position, 
                View convertView, 
                ViewGroup parent)

Parameters
position int

convertView View

parent ViewGroup

Returns
View

hasStableIds

boolean hasStableIds ()

Returns
boolean

newDropDownView

added in version 22.1.0
View newDropDownView (Context context, 
                Cursor cursor, 
                ViewGroup parent)

Makes a new drop down 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.

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

Returns
View the newly created view.

newView

added in version 22.1.0
View newView (Context context, 
                Cursor cursor, 
                ViewGroup parent)

Makes a new 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.

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

Returns
View the newly created view.

runQueryOnBackgroundThread

added in version 22.1.0
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 CharSequence: the constraint with which the query must be filtered

Returns
Cursor a Cursor representing the results of the new query

setFilterQueryProvider

added in version 22.1.0
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 FilterQueryProvider: the filter query provider or null to remove it

swapCursor

added in version 22.1.0
Cursor swapCursor (Cursor newCursor)

Swap in a new Cursor, returning the old Cursor. Unlike changeCursor(Cursor), the returned old Cursor is not closed.

Parameters
newCursor Cursor: The new cursor to be used.

Returns
Cursor Returns the previously set Cursor, or null if there was not one. If the given new Cursor is the same instance is the previously set Cursor, null is also returned.

Protected methods

init

added in version 22.1.0
void init (Context context, 
                Cursor c, 
                boolean autoRequery)

This method was deprecated in API level 22.1.0.
Don't use this, use the normal constructor. This will be removed in the future.

Parameters
context Context

c Cursor

autoRequery boolean

onContentChanged

added in version 22.1.0
void onContentChanged ()

Called when the ContentObserver on the cursor receives a change notification. The default implementation provides the auto-requery logic, but may be overridden by sub classes.

See also: