java.lang.Object | ||||
↳ | android.widget.BaseAdapter | |||
↳ | android.widget.CursorAdapter | |||
↳ | android.widget.ResourceCursorAdapter | |||
↳ | android.widget.SimpleCursorAdapter |
An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. You can specify which columns you want, which views you want to display the columns, and the XML file that defines the appearance of these views. Binding occurs in two phases. First, if a SimpleCursorAdapter.ViewBinder is available, setViewValue(android.view.View, android.database.Cursor, int) is invoked. If the returned value is true, binding has occured. If the returned value is false and the view to bind is a TextView, setViewText(TextView, String) is invoked. If the returned value is false and the view to bind is an ImageView, setViewImage(ImageView, String) is invoked. If no appropriate binding can be found, an IllegalStateException is thrown. If this adapter is used with filtering, for instance in an AutoCompleteTextView, you can use the SimpleCursorAdapter.CursorToStringConverter and the FilterQueryProvider interfaces to get control over the filtering process. You can refer to convertToString(android.database.Cursor) and runQueryOnBackgroundThread(CharSequence) for more information.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
SimpleCursorAdapter.CursorToStringConverter | This class can be used by external clients of SimpleCursorAdapter to define how the Cursor should be converted to a String. | ||||||||||
SimpleCursorAdapter.ViewBinder | This class can be used by external clients of SimpleCursorAdapter to bind values fom the Cursor to views. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.widget.Adapter
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Binds all of the field names passed into the "to" parameter of the
constructor with their corresponding cursor columns as specified in the
"from" parameter.
| |||||||||||
Change the underlying cursor to a new cursor.
| |||||||||||
Change the cursor and change the column-to-view mappings at the same time.
| |||||||||||
Returns a CharSequence representation of the specified Cursor as defined
by the current CursorToStringConverter.
| |||||||||||
Returns the converter used to convert the filtering Cursor
into a String.
| |||||||||||
Return the index of the column used to get a String representation
of the Cursor.
| |||||||||||
Returns the SimpleCursorAdapter.ViewBinder used to bind data to views.
| |||||||||||
Makes a new drop down view to hold the data pointed to by cursor.
| |||||||||||
Inflates view(s) from the specified XML file.
| |||||||||||
Sets the converter used to convert the filtering Cursor
into a String.
| |||||||||||
Defines the index of the column in the Cursor used to get a String
representation of that Cursor.
| |||||||||||
Sets the binder used to bind data to views.
| |||||||||||
Called by bindView() to set the image for an ImageView but only if
there is no existing ViewBinder or if the existing ViewBinder cannot
handle binding to an ImageView.
| |||||||||||
Called by bindView() to set the text for a TextView but only if
there is no existing ViewBinder or if the existing ViewBinder cannot
handle binding to an TextView.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class android.widget.ResourceCursorAdapter
| |||||||||||
From class android.widget.CursorAdapter
| |||||||||||
From class android.widget.BaseAdapter
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface android.widget.Adapter
| |||||||||||
From interface android.widget.Filterable
| |||||||||||
From interface android.widget.ListAdapter
| |||||||||||
From interface android.widget.SpinnerAdapter
|
Constructor.
context | The context where the ListView associated with this SimpleListItemFactory is running |
---|---|
layout | resource identifier of a layout file that defines the views for this list item. Thelayout file should include at least those named views defined in "to" |
c | The database cursor. Can be null if the cursor is not available yet. |
from | A list of column names representing the data to bind to the UI. Can be null if the cursor is not available yet. |
to | The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter. Can be null if the cursor is not available yet. |
Binds all of the field names passed into the "to" parameter of the constructor with their corresponding cursor columns as specified in the "from" parameter. Binding occurs in two phases. First, if a SimpleCursorAdapter.ViewBinder is available, setViewValue(android.view.View, android.database.Cursor, int) is invoked. If the returned value is true, binding has occured. If the returned value is false and the view to bind is a TextView, setViewText(TextView, String) is invoked. If the returned value is false and the view to bind is an ImageView, setViewImage(ImageView, String) is invoked. If no appropriate binding can be found, an IllegalStateException is thrown.
view | Existing view, returned earlier by newView |
---|---|
context | Interface to application's global information |
cursor | The cursor from which to get the data. The cursor is already moved to the correct position. |
IllegalStateException | if binding cannot occur |
---|
Change the underlying cursor to a new cursor. If there is an existing cursor it will be closed.
c | the new cursor to be used |
---|
Change the cursor and change the column-to-view mappings at the same time.
c | The database cursor. Can be null if the cursor is not available yet. |
---|---|
from | A list of column names representing the data to bind to the UI. Can be null if the cursor is not available yet. |
to | The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter. Can be null if the cursor is not available yet. |
Returns a CharSequence representation of the specified Cursor as defined by the current CursorToStringConverter. If no CursorToStringConverter has been set, the String conversion column is used instead. If the conversion column is -1, the returned String is empty if the cursor is null or Cursor.toString().
cursor | the Cursor to convert to a CharSequence |
---|
Returns the converter used to convert the filtering Cursor into a String.
Return the index of the column used to get a String representation of the Cursor.
Returns the SimpleCursorAdapter.ViewBinder used to bind data to views.
Makes a new drop down view to hold the data pointed to by cursor.
context | Interface to application's global information |
---|---|
cursor | 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 to |
Inflates view(s) from the specified XML file.
context | Interface to application's global information |
---|---|
cursor | 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 to |
Sets the converter used to convert the filtering Cursor into a String.
cursorToStringConverter | the Cursor to String converter, or null to remove the converter |
---|
Defines the index of the column in the Cursor used to get a String representation of that Cursor. The column is used to convert the Cursor to a String only when the current CursorToStringConverter is null.
stringConversionColumn | a valid index in the current Cursor or -1 to use the default conversion mechanism |
---|
Sets the binder used to bind data to views.
viewBinder | the binder used to bind data to views, can be null to remove the existing binder |
---|
Called by bindView() to set the image for an ImageView but only if there is no existing ViewBinder or if the existing ViewBinder cannot handle binding to an ImageView. By default, the value will be treated as an image resource. If the value cannot be used as an image resource, the value is used as an image Uri. Intended to be overridden by Adapters that need to filter strings retrieved from the database.
v | ImageView to receive an image |
---|---|
value | the value retrieved from the cursor |
Called by bindView() to set the text for a TextView but only if there is no existing ViewBinder or if the existing ViewBinder cannot handle binding to an TextView. Intended to be overridden by Adapters that need to filter strings retrieved from the database.
v | TextView to receive text |
---|---|
text | the text to be set for the TextView |