public abstract class CursorAdapter
extends BaseAdapter implements Filterable, ThemedSpinnerAdapter
| java.lang.Object | ||
| android.widget.BaseAdapter | ||
| android.widget.CursorAdapter | ||
| |
| |
将数据从 Cursor暴露给 ListView小部件的适配器。
游标必须包含一个名为“_id”的列,否则这个类将不起作用。 此外,如果合并游标在其“_id”列中具有重叠值,则对该类使用MergeCursor将不起作用。
常量(Constants) |
|
|---|---|
int |
FLAG_AUTO_REQUERY 此常数在API级别11中已弃用。此选项不鼓励使用,因为它导致在应用程序的UI线程上执行游标查询,因此可能导致响应性较差甚至出现应用程序无响应错误。 作为替代,使用 |
int |
FLAG_REGISTER_CONTENT_OBSERVER 如果设置了适配器,则会在光标上注册一个内容观察器,并在发出通知时调用 |
Inherited constants |
|---|
android.widget.Adapter
|
Public constructors |
|
|---|---|
CursorAdapter(Context context, Cursor c) 此构造函数在API级别11中已弃用。此选项不鼓励,因为它导致在应用程序的UI线程上执行游标查询,因此可能导致响应性较差甚至出现应用程序无响应错误。 作为替代,使用 |
|
CursorAdapter(Context context, Cursor c, boolean autoRequery) 允许控制自动重新查询的构造函数。 |
|
CursorAdapter(Context context, Cursor c, int flags) 推荐的构造函数。 |
|
公共方法(Public methods) |
|
|---|---|
abstract void |
bindView(View view, Context context, Cursor cursor) 将现有视图绑定到光标指向的数据 |
void |
changeCursor(Cursor cursor) 将底层游标更改为新的游标。 |
CharSequence |
convertToString(Cursor cursor) 将光标转换为CharSequence。 |
int |
getCount() 本适配器所代表的数据集中有多少项目。 |
Cursor |
getCursor() 返回游标。 |
View |
getDropDownView(int position, View convertView, ViewGroup parent) |
Resources.Theme |
getDropDownViewTheme() 返回以前通过调用 |
Filter |
getFilter() 返回可用于使用过滤模式约束数据的过滤器。 |
FilterQueryProvider |
getFilterQueryProvider() 返回用于过滤的查询过滤器提供程序。 |
Object |
getItem(int position) 获取与数据集中指定位置关联的数据项。 |
long |
getItemId(int position) 获取与列表中指定位置关联的行ID。 |
View |
getView(int position, View convertView, ViewGroup parent) 获取显示数据集中指定位置的数据的视图。 |
boolean |
hasStableIds() 指示项目id在基础数据更改期间是否稳定。 |
View |
newDropDownView(Context context, Cursor cursor, ViewGroup parent) 创建一个新的下拉视图来保存指针指向的数据。 |
abstract View |
newView(Context context, Cursor cursor, ViewGroup parent) 创建一个新视图来保存指针指向的数据。 |
Cursor |
runQueryOnBackgroundThread(CharSequence constraint) 使用指定的约束运行查询。 |
void |
setDropDownViewTheme(Resources.Theme theme) 设置 |
void |
setFilterQueryProvider(FilterQueryProvider filterQueryProvider) 设置用于过滤当前游标的查询过滤器提供程序。 |
Cursor |
swapCursor(Cursor newCursor) 交换一个新的游标,返回旧的游标。 |
Protected methods |
|
|---|---|
void |
init(Context context, Cursor c, boolean autoRequery) 此方法在API级别11中已弃用。不要使用此方法,请使用正常的构造方法。 这将在未来被删除。 |
void |
onContentChanged() 当光标上的 |
继承方法(Inherited methods) |
|
|---|---|
android.widget.BaseAdapter
|
|
java.lang.Object
|
|
android.widget.ListAdapter
|
|
android.widget.SpinnerAdapter
|
|
android.widget.Filterable
|
|
android.widget.ThemedSpinnerAdapter
|
|
android.widget.Adapter
|
|
int FLAG_AUTO_REQUERY
此常数在API级别11中已弃用。
不鼓励使用此选项,因为它会导致在应用程序的UI线程上执行游标查询,因此可能导致响应性较差甚至出现应用程序无响应错误。 作为替代,使用LoaderManager和CursorLoader 。
如果设置了适配器,则会在传递内容更改通知时在光标上调用requery()。 意味着FLAG_REGISTER_CONTENT_OBSERVER 。
常数值:1(0x00000001)
int FLAG_REGISTER_CONTENT_OBSERVER
如果设置,适配器将在光标上注册一个内容观察器,并在通知进入时调用onContentChanged()使用此标志时请小心:您需要从适配器中取消当前光标以避免由于注册的观察者而导致泄漏。 使用带有CursorLoader的CursorAdapter时,不需要此标志。
常量值:2(0x00000002)
CursorAdapter (Context context, Cursor c)
此构造函数在API级别11中已弃用。
不鼓励使用此选项,因为它会导致在应用程序的UI线程上执行游标查询,因此可能导致响应性较差甚至出现应用程序无响应错误。 作为替代,使用LoaderManager和CursorLoader 。
始终启用自动重新查询的构造函数。
| 参数(Parameters) | |
|---|---|
context |
Context: The context |
c |
Cursor: The cursor from which to get the data. |
CursorAdapter (Context context, Cursor c, boolean autoRequery)
允许控制自动重新查询的构造函数。 建议你不要使用这个,而是CursorAdapter(Context, Cursor, int) 。 使用此构造函数时,将始终设置FLAG_REGISTER_CONTENT_OBSERVER 。
| 参数(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 (Context context, Cursor c, int flags)
推荐的构造函数。
| 参数(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. |
void bindView (View view, Context context, Cursor 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. |
void changeCursor (Cursor cursor)
将底层游标更改为新的游标。 如果有一个现有的游标,它将被关闭。
| 参数(Parameters) | |
|---|---|
cursor |
Cursor: The new cursor to be used |
CharSequence convertToString (Cursor cursor)
将光标转换为CharSequence。 子类应该重写此方法来转换它们的结果。 默认实现返回空值的空字符串或值的默认字符串表示形式。
| 参数(Parameters) | |
|---|---|
cursor |
Cursor: the cursor to convert to a CharSequence |
| 返回(Returns) | |
|---|---|
CharSequence |
a CharSequence representing the value |
int getCount ()
本适配器所代表的数据集中有多少项目。
| 返回(Returns) | |
|---|---|
int |
Count of items. |
也可以看看:
View getDropDownView (int position, View convertView, ViewGroup parent)
获取 View ,它在下拉式弹出 View中显示数据集中指定位置的数据。
| 参数(Parameters) | |
|---|---|
position |
int: index of the item whose view we want. |
convertView |
View: 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 |
ViewGroup: the parent that this view will eventually be attached to |
| 返回(Returns) | |
|---|---|
View |
a View corresponding to the data at the specified position. |
Resources.Theme getDropDownViewTheme ()
返回以前通过调用 setDropDownViewTheme(Theme)设置的值。
| 返回(Returns) | |
|---|---|
Resources.Theme |
the Resources.Theme against which drop-down views are inflated, or null if one has not been explicitly set |
Filter getFilter ()
返回可用于使用过滤模式约束数据的过滤器。
这种方法通常由 Adapter类实现。
| 返回(Returns) | |
|---|---|
Filter |
a filter used to constrain data |
FilterQueryProvider getFilterQueryProvider ()
返回用于过滤的查询过滤器提供程序。 当提供程序为空时,不会进行过滤。
| 返回(Returns) | |
|---|---|
FilterQueryProvider |
the current filter query provider or null if it does not exist |
Object getItem (int position)
获取与数据集中指定位置关联的数据项。
| 参数(Parameters) | |
|---|---|
position |
int: Position of the item whose data we want within the adapter's data set. |
| 返回(Returns) | |
|---|---|
Object |
The data at the specified position. |
也可以看看:
long getItemId (int position)
获取与列表中指定位置关联的行ID。
| 参数(Parameters) | |
|---|---|
position |
int: The position of the item within the adapter's data set whose row id we want. |
| 返回(Returns) | |
|---|---|
long |
The id of the item at the specified position. |
也可以看看:
View getView (int position, View convertView, ViewGroup parent)
获取显示数据集中指定位置的数据的视图。 您可以手动创建视图或从XML布局文件中对其进行膨胀。 当视图膨胀时,父视图(GridView,ListView ...)将应用默认布局参数,除非您使用inflate(int, android.view.ViewGroup, boolean)指定根视图并防止附加到根。
| 参数(Parameters) | |
|---|---|
position |
int: The position of the item within the adapter's data set of the item whose view we want. |
convertView |
View: 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 getViewTypeCount() and getItemViewType(int)). |
parent |
ViewGroup: The parent that this view will eventually be attached to |
| 返回(Returns) | |
|---|---|
View |
A View corresponding to the data at the specified position. |
boolean hasStableIds ()
指示项目id在基础数据更改期间是否稳定。
| 返回(Returns) | |
|---|---|
boolean |
True if the same id always refers to the same object. |
View newDropDownView (Context context, Cursor cursor, ViewGroup parent)
创建一个新的下拉视图来保存指针指向的数据。
| 参数(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. |
View newView (Context context, Cursor cursor, ViewGroup parent)
创建一个新视图来保存指针指向的数据。
| 参数(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. |
Cursor runQueryOnBackgroundThread (CharSequence constraint)
使用指定的约束运行查询。 该查询由连接到此适配器的过滤器请求。 查询由FilterQueryProvider提供。 如果未指定提供者,则不会过滤并返回当前游标。 在此方法返回后,将生成的光标传递给changeCursor(Cursor)并关闭前一个光标。 此方法总是在后台线程上执行,而不是在应用程序的主线程(或UI线程)上执行。合约:当约束为空或空时,必须返回在任何过滤之前的原始结果。
| 参数(Parameters) | |
|---|---|
constraint |
CharSequence: the constraint with which the query must be filtered |
| 返回(Returns) | |
|---|---|
Cursor |
a Cursor representing the results of the new query |
void setDropDownViewTheme (Resources.Theme theme)
设置 Resources.Theme ,其下拉视图被充满。
默认情况下,下拉视图会根据传递给适配器构造函数的 Context的主题进行膨胀。
| 参数(Parameters) | |
|---|---|
theme |
Resources.Theme: the theme against which to inflate drop-down views or null to use the theme from the adapter's context |
void setFilterQueryProvider (FilterQueryProvider filterQueryProvider)
设置用于过滤当前游标的查询过滤器提供程序。 当此适配器的客户端请求过滤时,会调用提供程序的runQuery(CharSequence)方法。
| 参数(Parameters) | |
|---|---|
filterQueryProvider |
FilterQueryProvider: the filter query provider or null to remove it |
Cursor swapCursor (Cursor newCursor)
交换一个新的游标,返回旧的游标。 与changeCursor(Cursor)不同,返回的旧游标未关闭。
| 参数(Parameters) | |
|---|---|
newCursor |
Cursor: The new cursor to be used. |
| 返回(Returns) | |
|---|---|
Cursor |
Returns the previously set Cursor, or null if there wasa not one. If the given new Cursor is the same instance is the previously set Cursor, null is also returned. |
void init (Context context, Cursor c, boolean autoRequery)
This method was deprecated in API level 11.
Don't use this, use the normal constructor. This will be removed in the future.
| 参数(Parameters) | |
|---|---|
context |
Context
|
c |
Cursor
|
autoRequery |
boolean
|
void onContentChanged ()
当光标上的ContentObserver收到更改通知时调用。 默认实现提供了自动重新查询逻辑,但可能会被子类覆盖。
也可以看看: