Structure
Inheritance relationship
Public class simplecusroradapter extends
Resourcecusoradpater
Java. Lang. Object
Android. widget. baseadapter
Android. widget. cursoradapter
Android. widget. resourcecusoradapter
Android. widget. simplecusoradapter
Class Overview
This is an easy-to-use adapter class that maps cursor to texiview or imageview. For example, if you want to set three columns to be displayed, after binding, the view will display the columns you have set. Of course, the view's appearance is defined in the XML file, you only need to bind the class to the view. Binding to a view has two phases. Phase 1: IfSimpleCursorAdapter.ViewBinderAvailable, will callsetViewValue(android.view.View,
android.database.Cursor, int)Method. If this method returns true, the binding is successful. Otherwise, false is returned. In the second stage, simplecursoradapter starts to bind itself internally. The process is like this. If it is bound to textview, call setviewtext (). If it is bound to imageview, call setviewimage (). If the view is not textview or imageview, an illegalstateexception exception is thrown. When using an adapter with a filter, for example, an example of autocompletetextview in apidemo can be usedSimpleCursorAdapter.CursorToStringConverterAnd Interfaces
FilterQueryProviderTo control the filtering process. For more information, seeconvertToString(android.database.Cursor)
AndrunQueryOnBackgroundThread(CharSequence).
Internal class
Public interfaceSimplecusoradapter. viewbinder
You can use simplecursoradapter. viewbinder to bind a cursor to a view.
Public interfaceSimplecusoradapter. cursortostringconverter
You can use simplecursoradapter. cursortostringconverter to define how to convert cursor to a string.
Constructor
PublicSimplecursoradapter(Context, int layout, cursor C, string [] From, int [])
The constructor starts auto-requery ).
This constructor has been marked as obsolete (@ deprecated)
.
This method is not recommended. The cursor query operation is executed in the UI thread of the application, resulting in no response. Another method is to use loadermanager and cursorloader.
(Note: 3.0 this constructor is not recommended)
Parameters
Context application context, specifically in the context where the listview is located.
The resource location identifier of the layout file, that is, the item in listview is identified. The layout file contains at least the incoming values in the parameter ".
Database C cursor. If the cursor is unavailable, it is null.
The from column name list indicates the columns to be bound to the UI. If the cursor is unavailable, it is null.
To display the columns in the parameter "from", that is, the view in listview displays the column values of the parameter "from". These views should all be textviews. If the cursor is unavailable, it is null.
PublicSimplecursoradapter(Context, int layout, cursor C, string [] From, int []
To, int flags)
This adapter class is a standard constructor. (Translator's note: 3.0 newly added constructor)
Parameters
Context application context, specifically in the context where the listview is located.
The resource location identifier of the layout file, that is, the item in listview is identified. The layout file contains at least the incoming values in the parameter ".
Database C cursor. If the cursor is unavailable, it is null.
The from column name list indicates the columns to be bound to the UI. If the cursor is unavailable, it is null.
To display the columns in the parameter "from", that is, the view in listview displays the column values of the parameter "from". These views should all be textviews. If the cursor is unavailable, it is null.
Flags is used to determine the behavior of the adapter. (Translator's note: we recommend that you pass cursoradapter. flag_register_content_observer in android3.0. The setting flag is used to add a listener to monitor whether the data of the cursor parameter has changed .)
Common Methods
Public voidBindView(View view, context, cursor)
Bind the parameters from in all constructors to the parameter to (view resource ID) one by one ). Binding to a view has two phases. Phase 1: IfSimpleCursorAdapter.ViewBinderAvailable, will callsetViewValue(android.view.View,
android.database.Cursor, int)Method. If this method returns true, the binding is successful. Otherwise, false is returned. In the second stage, simplecursoradapter starts to bind itself internally. The process is like this. If it is bound to textview, call setviewtext (). If it is bound to imageview, call setviewimage (). If the view is not textview or imageview, an illegalstateexception exception is thrown.
Parameters
The existing view object, which is newly created earlier.
Context application context.
Cursor database cursor. The cursor has been moved to the specified position.
Exception
Illegalstateexception: If the bound view is not textview or imageview, this exception is thrown.
See
bindView(android.view.View, android.content.Context,
android.database.Cursor)
getViewBinder()
setViewBinder(android.widget.SimpleCursorAdapter.ViewBinder)
setViewImage(ImageView, String)
setViewText(TextView, String)
Public voidChangecursorandcolumns(Cursor C, string [] From, int [])
You can also change the ing between cursor and view.
Parameters
Database C cursor. If the cursor is unavailable, it is null.
The from column name list indicates the columns to be bound to the UI. If the cursor is unavailable, it is null.
To display the columns in the parameter "from", that is, the view in listview displays the column values of the parameter "from". These views should all be textviews. If the cursor is unavailable, it is null.
Public charsequenceConverttostring(Cursor)
Implemented through the cursortostringconverter interface and returns a value of the charsequence type to indicate the specified cursor. If cursortostringconverter is not set, the conversion is performed in another way. If the number of columns is-1 or the cursor is null, an empty string is returned. Otherwise, cursor. tostring () is returned ().
Parameters
The database cursor that cursor converts to charsequence.
Return Value
Return a charsequence type that is not null to represent the cursor parameter.
Public simplecursoradapter. cursortostringconverter
Getcursortostringconverter()
Return the implementation of the custom simplecursoradapter. cursortostringconverter.
Return Value
If simplecursoradapter. cursortostringconverter is not set, it is null.
Reference
setCursorToStringConverter(android.widget.SimpleCursorAdapter.CursorToStringConverter)
getStringConversionColumn()
setStringConversionColumn(int)
convertToString(android.database.Cursor)
Public intGetstringconversioncolumn()
Returns the position of a string-type column.
Return Value
Returns the position of a column. If not,-1 is returned.
Reference
convertToString(android.database.Cursor)
setStringConversionColumn(int)
setCursorToStringConverter(android.widget.SimpleCursorAdapter.CursorToStringConverter)
getCursorToStringConverter()
Public simplecursoradapter. viewbinder
Getviewbinder()
Return simplecursoradapter. viewbinder reference. This viewbinder is used to bind data to the view.
Return Value
If viewbinder does not exist, null is returned.
Reference
bindView(android.view.View, android.content.Context,
android.database.Cursor)
setViewBinder(android.widget.SimpleCursorAdapter.ViewBinder)
Public voidSetcursortostringconverter(Simplecursoradapter. cursortostringconverter)
Set the string converter.
Parameters
Cursortostringconverter string converter. If it is set to null, it means that it is removed.
Reference
setCursorToStringConverter(android.widget.SimpleCursorAdapter.CursorToStringConverter)
getStringConversionColumn()
setStringConversionColumn(int)
convertToString(android.database.Cursor)
Public voidSetstringconversioncolumn(INT stringconversioncolumn)
Set the position where the column in cursor is to be converted to the string type. However, this column is converted by default only when cursortostringconverter is not set.
Parameters
The position of the stringconversioncolumn. If the parameter is-1, the default conversion mechanism is used.
Reference
convertToString(android.database.Cursor)
getStringConversionColumn()
setCursorToStringConverter(android.widget.SimpleCursorAdapter.CursorToStringConverter)
getCursorToStringConverter()
Public voidSetviewbinder(Simplecursoradapter. viewbinder)
Set the view binder.
Parameters
Viewbinder view binder, which can be null to delete an existing binder.
Reference
bindView(android.view.View, android.content.Context,
android.database.Cursor)
getViewBinder()
Public voidSetviewimage(Imageview V, string value)
If viewbinder does not exist or if viewbinder is not bound to imageview (that is, setviewvalue () returns false), this method is called by BindView () to set images for imageview. By default, the parameter value is treated as the image resource ID. Otherwise, it is treated as the image Uri. You can also use filters to get more flexible settings.
Parameters
V Image Control Reference
Value image resource ID, obtained from cursor.
Public voidSetviewtext(Textview V, string text)
This method is called by BindView () to set text for textview only when viewbinder does not exist or when viewbinder does not bind textview (that is, setviewvalue () returns false. You can use the rewrite adapter to retrieve and filter strings from the database.
Parameters
V text Control Reference
Value is the text information set by the text control ).
Public cursorSwapcursor(Cursor C)
Exchange two cursor columns and their data, and finally return the old cursor. Different fromchangeCursor(Cursor)Instead of shutting down the old cursor, the old cursor will return. Note:
3.0 new methods)
Parameters
C. The new cursor object.
Return Value
The old cursor reference is returned. If the cursor parameter is unavailable, null is returned. If the parameter cursor is the same as the original cursor reference, null is also returned.
Supplement
Article Selection
Examples of arrayadapter and simplecursoradapter
Android API: simplecursoradapter ()