CursorAdapter


abstract class CursorAdapter : BaseAdapter, Filterable

Known direct subclasses
ResourceCursorAdapter

Static library support version of the framework's android.widget.ResourceCursorAdapter.

Known indirect subclasses
SimpleCursorAdapter

Static library support version of the framework's android.widget.SimpleCursorAdapter.


Static library support version of the framework's android.widget.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

const Int

This property is deprecated.

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.

const Int

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

Public constructors

CursorAdapter(context: Context!, c: Cursor!)

This function is deprecated.

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.

CursorAdapter(context: Context!, c: Cursor!, autoRequery: Boolean)

Constructor that allows control over auto-requery.

CursorAdapter(context: Context!, c: Cursor!, flags: Int)

Recommended constructor.

Public functions

abstract Unit
bindView(view: View!, context: Context!, cursor: Cursor!)

Bind an existing view to the data pointed to by cursor

Unit
changeCursor(cursor: Cursor!)

Change the underlying cursor to a new cursor.

CharSequence!

Converts the cursor into a CharSequence.

Int
Cursor!

Returns the cursor.

View!
getDropDownView(position: Int, convertView: View!, parent: ViewGroup!)
Filter!
FilterQueryProvider!

Returns the query filter provider used for filtering.

Any!
getItem(position: Int)
Long
getItemId(position: Int)
View!
getView(position: Int, convertView: View!, parent: ViewGroup!)
Boolean
View!
newDropDownView(context: Context!, cursor: Cursor!, parent: ViewGroup!)

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

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

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

Cursor!

Runs a query with the specified constraint.

Unit

Sets the query filter provider used to filter the current Cursor.

Cursor!
swapCursor(newCursor: Cursor!)

Swap in a new Cursor, returning the old Cursor.

Protected functions

Unit
init(context: Context!, c: Cursor!, autoRequery: Boolean)

This function is deprecated.

Don't use this, use the normal constructor.

Unit

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

Inherited Constants

From android.widget.Adapter
const Int
const Int
NO_SELECTION = -2147483648

Constants

FLAG_AUTO_REQUERY

Added in 1.0.0
Deprecated in 1.0.0
const val FLAG_AUTO_REQUERY = 1: Int

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

FLAG_REGISTER_CONTENT_OBSERVER

Added in 1.0.0
const val FLAG_REGISTER_CONTENT_OBSERVER = 2: Int

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 android.content.CursorLoader.

Public constructors

CursorAdapter

Added in 1.0.0
Deprecated in 1.0.0
CursorAdapter(context: Context!, c: Cursor!)

Constructor that always enables auto-requery.

Parameters
context: Context!

The context

c: Cursor!

The cursor from which to get the data.

CursorAdapter

Added in 1.0.0
CursorAdapter(context: Context!, c: Cursor!, autoRequery: Boolean)

Constructor that allows control over auto-requery. It is recommended you not use this, but instead CursorAdapter. 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 1.0.0
CursorAdapter(context: Context!, c: Cursor!, flags: Int)

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 functions

bindView

Added in 1.0.0
abstract fun bindView(view: View!, context: Context!, cursor: Cursor!): Unit

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 1.0.0
fun changeCursor(cursor: Cursor!): Unit

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 1.0.0
fun convertToString(cursor: Cursor!): CharSequence!

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 1.0.0
fun getCount(): Int
See also
getCount

getCursor

Added in 1.0.0
fun getCursor(): Cursor!

Returns the cursor.

Returns
Cursor!

the cursor.

getDropDownView

fun getDropDownView(position: Int, convertView: View!, parent: ViewGroup!): View!

getFilter

Added in 1.0.0
fun getFilter(): Filter!

getFilterQueryProvider

Added in 1.0.0
fun getFilterQueryProvider(): FilterQueryProvider!

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 1.0.0
fun getItem(position: Int): Any!
See also
getItem

getItemId

Added in 1.0.0
fun getItemId(position: Int): Long
See also
getItemId

getView

Added in 1.0.0
fun getView(position: Int, convertView: View!, parent: ViewGroup!): View!
See also
getView

hasStableIds

fun hasStableIds(): Boolean

newDropDownView

Added in 1.0.0
fun newDropDownView(context: Context!, cursor: Cursor!, parent: ViewGroup!): View!

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 1.0.0
abstract fun newView(context: Context!, cursor: Cursor!, parent: ViewGroup!): View!

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 1.0.0
fun runQueryOnBackgroundThread(constraint: CharSequence!): Cursor!

Runs a query with the specified constraint. This query is requested by the filter attached to this adapter. The query is provided by a android.widget.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 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 1.0.0
fun setFilterQueryProvider(filterQueryProvider: FilterQueryProvider!): Unit

Sets the query filter provider used to filter the current Cursor. The provider's runQuery 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 1.0.0
fun swapCursor(newCursor: Cursor!): Cursor!

Swap in a new Cursor, returning the old Cursor. Unlike changeCursor, 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 functions

init

Added in 1.0.0
Deprecated in 1.0.0
protected fun init(context: Context!, c: Cursor!, autoRequery: Boolean): Unit

onContentChanged

Added in 1.0.0
protected fun onContentChanged(): Unit

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
onChange