public abstract class CursorAdapter extends BaseAdapter implements Filterable
Modifier and Type | Field and Description |
---|---|
static int |
FLAG_AUTO_REQUERY
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. As an alternative,
use
LoaderManager with a CursorLoader . |
static 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. |
protected boolean |
mAutoRequery
This field should be made private, so it is hidden from the SDK.
|
protected android.widget.CursorAdapter.ChangeObserver |
mChangeObserver
This field should be made private, so it is hidden from the SDK.
|
protected Context |
mContext
This field should be made private, so it is hidden from the SDK.
|
protected Cursor |
mCursor
This field should be made private, so it is hidden from the SDK.
|
protected android.widget.CursorFilter |
mCursorFilter
This field should be made private, so it is hidden from the SDK.
|
protected DataSetObserver |
mDataSetObserver
This field should be made private, so it is hidden from the SDK.
|
protected boolean |
mDataValid
This field should be made private, so it is hidden from the SDK.
|
protected FilterQueryProvider |
mFilterQueryProvider
This field should be made private, so it is hidden from the SDK.
|
protected int |
mRowIDColumn
This field should be made private, so it is hidden from the SDK.
|
IGNORE_ITEM_VIEW_TYPE, NO_SELECTION
Constructor and Description |
---|
CursorAdapter(Context context,
Cursor c)
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. 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.
|
Modifier and Type | Method and Description |
---|---|
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()
How many items are in the data set represented by this Adapter.
|
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.
|
Object |
getItem(int position)
Get the data item associated with the specified position in the data set.
|
long |
getItemId(int position)
Get the row id associated with the specified position in the list.
|
View |
getView(int position,
View convertView,
ViewGroup parent)
Get a View that displays the data at the specified position in the data set.
|
boolean |
hasStableIds()
Indicates whether the item ids are stable across changes to the
underlying data.
|
protected void |
init(Context context,
Cursor c,
boolean autoRequery)
Deprecated.
Don't use this, use the normal constructor. This will
be removed in the future.
|
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.
|
protected void |
onContentChanged()
Called when the
ContentObserver on the cursor receives a change notification. |
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.
|
areAllItemsEnabled, getItemViewType, getViewTypeCount, isEmpty, isEnabled, notifyDataSetChanged, notifyDataSetInvalidated, registerDataSetObserver, unregisterDataSetObserver
protected boolean mDataValid
protected boolean mAutoRequery
protected Cursor mCursor
protected Context mContext
protected int mRowIDColumn
protected android.widget.CursorAdapter.ChangeObserver mChangeObserver
protected DataSetObserver mDataSetObserver
protected android.widget.CursorFilter mCursorFilter
protected FilterQueryProvider mFilterQueryProvider
@Deprecated public static final int FLAG_AUTO_REQUERY
LoaderManager
with a CursorLoader
.FLAG_REGISTER_CONTENT_OBSERVER
.public static final int FLAG_REGISTER_CONTENT_OBSERVER
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
.@Deprecated public CursorAdapter(Context context, Cursor c)
LoaderManager
with a CursorLoader
.c
- The cursor from which to get the data.context
- The contextpublic CursorAdapter(Context context, Cursor c, boolean autoRequery)
CursorAdapter(Context, Cursor, int)
.
When using this constructor, FLAG_REGISTER_CONTENT_OBSERVER
will always be set.c
- The cursor from which to get the data.context
- The contextautoRequery
- 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.public CursorAdapter(Context context, Cursor c, int flags)
c
- The cursor from which to get the data.context
- The contextflags
- Flags used to determine the behavior of the adapter; may
be any combination of FLAG_AUTO_REQUERY
and
FLAG_REGISTER_CONTENT_OBSERVER
.@Deprecated protected void init(Context context, Cursor c, boolean autoRequery)
public Cursor getCursor()
public int getCount()
Adapter
getCount
in interface Adapter
Adapter.getCount()
public Object getItem(int position)
Adapter
getItem
in interface Adapter
position
- Position of the item whose data we want within the adapter's
data set.Adapter.getItem(int)
public long getItemId(int position)
Adapter
getItemId
in interface Adapter
position
- The position of the item within the adapter's data set whose row id we want.Adapter.getItemId(int)
public boolean hasStableIds()
Adapter
hasStableIds
in interface Adapter
hasStableIds
in class BaseAdapter
public View getView(int position, View convertView, ViewGroup parent)
Adapter
LayoutInflater.inflate(int, android.view.ViewGroup, boolean)
to specify a root view and to prevent attachment to the root.getView
in interface Adapter
position
- The position of the item within the adapter's data set of the item whose view
we want.convertView
- The old view to reuse, if possible. Note: You should check that this view
is non-null and of an appropriate type before using. If it is not possible to convert
this view to display the correct data, this method can create a new view.
Heterogeneous lists can specify their number of view types, so that this View is
always of the right type (see Adapter.getViewTypeCount()
and
Adapter.getItemViewType(int)
).parent
- The parent that this view will eventually be attached toAdapter.getView(int, View, ViewGroup)
public View getDropDownView(int position, View convertView, ViewGroup parent)
SpinnerAdapter
Get a View
that displays in the drop down popup
the data at the specified position in the data set.
getDropDownView
in interface SpinnerAdapter
getDropDownView
in class BaseAdapter
position
- index of the item whose view we want.convertView
- the old view to reuse, if possible. Note: You should
check that this view is non-null and of an appropriate type before
using. If it is not possible to convert this view to display the
correct data, this method can create a new view.parent
- the parent that this view will eventually be attached toView
corresponding to the data at the
specified position.public abstract View newView(Context context, Cursor cursor, ViewGroup parent)
context
- Interface to application's global informationcursor
- 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 topublic View newDropDownView(Context context, Cursor cursor, ViewGroup parent)
context
- Interface to application's global informationcursor
- 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 topublic abstract void bindView(View view, Context context, Cursor cursor)
view
- Existing view, returned earlier by newViewcontext
- Interface to application's global informationcursor
- The cursor from which to get the data. The cursor is already
moved to the correct position.public void changeCursor(Cursor cursor)
cursor
- The new cursor to be usedpublic Cursor swapCursor(Cursor newCursor)
changeCursor(Cursor)
, the returned old Cursor is not
closed.newCursor
- 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.
cursor
- the cursor to convert to a CharSequencepublic Cursor runQueryOnBackgroundThread(CharSequence constraint)
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.constraint
- the constraint with which the query must be filteredgetFilter()
,
getFilterQueryProvider()
,
setFilterQueryProvider(android.widget.FilterQueryProvider)
public Filter getFilter()
Filterable
Returns a filter that can be used to constrain data with a filtering pattern.
This method is usually implemented by Adapter
classes.
getFilter
in interface Filterable
public FilterQueryProvider getFilterQueryProvider()
setFilterQueryProvider(android.widget.FilterQueryProvider)
,
runQueryOnBackgroundThread(CharSequence)
public void setFilterQueryProvider(FilterQueryProvider filterQueryProvider)
FilterQueryProvider.runQuery(CharSequence)
method is invoked when filtering is requested by a client of
this adapter.filterQueryProvider
- the filter query provider or null to remove itgetFilterQueryProvider()
,
runQueryOnBackgroundThread(CharSequence)
protected void onContentChanged()
ContentObserver
on the cursor receives a change notification.
The default implementation provides the auto-requery logic, but may be overridden by
sub classes.ContentObserver.onChange(boolean)