|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.widget.BaseAdapter
android.widget.CursorAdapter
android.widget.ResourceCursorAdapter
android.widget.SimpleCursorAdapter
public class 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,
SimpleCursorAdapter.ViewBinder.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
CursorAdapter.runQueryOnBackgroundThread(CharSequence) for more information.
| Nested Class Summary | |
|---|---|
static interface |
SimpleCursorAdapter.CursorToStringConverter
This class can be used by external clients of SimpleCursorAdapter to define how the Cursor should be converted to a String. |
static interface |
SimpleCursorAdapter.ViewBinder
This class can be used by external clients of SimpleCursorAdapter to bind values fom the Cursor to views. |
| Field Summary | |
|---|---|
protected int[] |
mFrom
A list of columns containing the data to bind to the UI. |
protected int[] |
mTo
A list of View ids representing the views to which the data must be bound. |
| Fields inherited from class android.widget.CursorAdapter |
|---|
mAutoRequery, mChangeObserver, mContext, mCursor, mCursorFilter, mDataSetObserver, mDataValid, mFilterQueryProvider, mRowIDColumn |
| Fields inherited from interface android.widget.Adapter |
|---|
IGNORE_ITEM_VIEW_TYPE, NO_SELECTION |
| Constructor Summary | |
|---|---|
SimpleCursorAdapter(Context context,
int layout,
Cursor c,
String[] from,
int[] to)
Constructor. |
|
| Method Summary | |
|---|---|
void |
bindView(View view,
Context context,
Cursor cursor)
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. |
void |
changeCursor(Cursor c)
Change the underlying cursor to a new cursor. |
CharSequence |
convertToString(Cursor cursor)
Returns a CharSequence representation of the specified Cursor as defined by the current CursorToStringConverter. |
SimpleCursorAdapter.CursorToStringConverter |
getCursorToStringConverter()
Returns the converter used to convert the filtering Cursor into a String. |
int |
getStringConversionColumn()
Return the index of the column used to get a String representation of the Cursor. |
SimpleCursorAdapter.ViewBinder |
getViewBinder()
Returns the SimpleCursorAdapter.ViewBinder used to bind data to views. |
void |
setCursorToStringConverter(SimpleCursorAdapter.CursorToStringConverter cursorToStringConverter)
Sets the converter used to convert the filtering Cursor into a String. |
void |
setStringConversionColumn(int stringConversionColumn)
Defines the index of the column in the Cursor used to get a String representation of that Cursor. |
void |
setViewBinder(SimpleCursorAdapter.ViewBinder viewBinder)
Sets the binder used to bind data to views. |
void |
setViewImage(ImageView v,
String value)
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. |
void |
setViewText(TextView v,
String text)
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. |
| Methods inherited from class android.widget.ResourceCursorAdapter |
|---|
newDropDownView, newView, setDropDownViewResource |
| Methods inherited from class android.widget.CursorAdapter |
|---|
getCount, getCursor, getDropDownView, getFilter, getFilterQueryProvider, getItem, getItemId, getView, hasStableIds, init, runQueryOnBackgroundThread, setFilterQueryProvider |
| Methods inherited from class android.widget.BaseAdapter |
|---|
areAllItemsEnabled, getItemViewType, getViewTypeCount, isEmpty, isEnabled, notifyDataSetChanged, notifyDataSetInvalidated, registerDataSetObserver, unregisterDataSetObserver |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected int[] mFrom
protected int[] mTo
| Constructor Detail |
|---|
public SimpleCursorAdapter(Context context,
int layout,
Cursor c,
String[] from,
int[] to)
context - The context where the ListView associated with this
SimpleListItemFactory is runninglayout - 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 UIto - 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.| Method Detail |
|---|
public void bindView(View view,
Context context,
Cursor cursor)
SimpleCursorAdapter.ViewBinder is available,
SimpleCursorAdapter.ViewBinder.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.
bindView in class CursorAdapterview - 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.
IllegalStateException - if binding cannot occurCursorAdapter.bindView(android.view.View,
android.content.Context, android.database.Cursor),
getViewBinder(),
setViewBinder(android.widget.SimpleCursorAdapter.ViewBinder),
setViewImage(ImageView, String),
setViewText(TextView, String)public SimpleCursorAdapter.ViewBinder getViewBinder()
SimpleCursorAdapter.ViewBinder used to bind data to views.
bindView(android.view.View, android.content.Context, android.database.Cursor),
setViewBinder(android.widget.SimpleCursorAdapter.ViewBinder)public void setViewBinder(SimpleCursorAdapter.ViewBinder viewBinder)
viewBinder - the binder used to bind data to views, can be null to
remove the existing binderbindView(android.view.View, android.content.Context, android.database.Cursor),
getViewBinder()
public void setViewImage(ImageView v,
String value)
v - ImageView to receive an imagevalue - the value retrieved from the cursor
public void setViewText(TextView v,
String text)
v - TextView to receive texttext - the text to be set for the TextViewpublic int getStringConversionColumn()
CursorAdapter.convertToString(android.database.Cursor),
setStringConversionColumn(int),
setCursorToStringConverter(android.widget.SimpleCursorAdapter.CursorToStringConverter),
getCursorToStringConverter()public void setStringConversionColumn(int stringConversionColumn)
stringConversionColumn - a valid index in the current Cursor or -1 to use the default
conversion mechanismCursorAdapter.convertToString(android.database.Cursor),
getStringConversionColumn(),
setCursorToStringConverter(android.widget.SimpleCursorAdapter.CursorToStringConverter),
getCursorToStringConverter()public SimpleCursorAdapter.CursorToStringConverter getCursorToStringConverter()
SimpleCursorAdapter.CursorToStringConvertersetCursorToStringConverter(android.widget.SimpleCursorAdapter.CursorToStringConverter),
getStringConversionColumn(),
setStringConversionColumn(int),
CursorAdapter.convertToString(android.database.Cursor)public void setCursorToStringConverter(SimpleCursorAdapter.CursorToStringConverter cursorToStringConverter)
cursorToStringConverter - the Cursor to String converter, or
null to remove the convertersetCursorToStringConverter(android.widget.SimpleCursorAdapter.CursorToStringConverter),
getStringConversionColumn(),
setStringConversionColumn(int),
CursorAdapter.convertToString(android.database.Cursor)public CharSequence convertToString(Cursor cursor)
convertToString in interface CursorFilter.CursorFilterClientconvertToString in class CursorAdaptercursor - the Cursor to convert to a CharSequence
public void changeCursor(Cursor c)
CursorAdapter
changeCursor in interface CursorFilter.CursorFilterClientchangeCursor in class CursorAdapterc - the new cursor to be used
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||