public class

SimpleDragSortCursorAdapter

extends ResourceDragSortCursorAdapter
java.lang.Object
   ↳ android.widget.BaseAdapter
     ↳ android.support.v4.widget.CursorAdapter
       ↳ com.mobeta.android.dslv.DragSortCursorAdapter
         ↳ com.mobeta.android.dslv.ResourceDragSortCursorAdapter
           ↳ com.mobeta.android.dslv.SimpleDragSortCursorAdapter

Class Overview

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 android.widget.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 android.widget.AutoCompleteTextView, you can use the android.widget.SimpleCursorAdapter.CursorToStringConverter and the android.widget.FilterQueryProvider interfaces to get control over the filtering process. You can refer to convertToString(android.database.Cursor) and runQueryOnBackgroundThread(CharSequence) for more information.

Summary

Nested Classes
interface SimpleDragSortCursorAdapter.CursorToStringConverter This class can be used by external clients of SimpleCursorAdapter to define how the Cursor should be converted to a String. 
interface SimpleDragSortCursorAdapter.ViewBinder This class can be used by external clients of SimpleCursorAdapter to bind values fom the Cursor to views. 
[Expand]
Inherited Constants
From class com.mobeta.android.dslv.DragSortCursorAdapter
From class android.support.v4.widget.CursorAdapter
From interface android.widget.Adapter
[Expand]
Inherited Fields
From class android.support.v4.widget.CursorAdapter
Public Constructors
SimpleDragSortCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to)
This constructor is 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 android.app.LoaderManager with a android.content.CursorLoader.
SimpleDragSortCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags)
Standard constructor.
Public Methods
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 changeCursorAndColumns(Cursor c, String[] from, int[] to)
Change the cursor and change the column-to-view mappings at the same time.
CharSequence convertToString(Cursor cursor)
Returns a CharSequence representation of the specified Cursor as defined by the current CursorToStringConverter.
SimpleDragSortCursorAdapter.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.
SimpleDragSortCursorAdapter.ViewBinder getViewBinder()
Returns the SimpleDragSortCursorAdapter.ViewBinder used to bind data to views.
void setCursorToStringConverter(SimpleDragSortCursorAdapter.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(SimpleDragSortCursorAdapter.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 a TextView.
Cursor swapCursor(Cursor c)
Swaps Cursor and clears list-Cursor mapping.
[Expand]
Inherited Methods
From class com.mobeta.android.dslv.ResourceDragSortCursorAdapter
From class com.mobeta.android.dslv.DragSortCursorAdapter
From class android.support.v4.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
From interface com.mobeta.android.dslv.DragSortListView.DragListener
From interface com.mobeta.android.dslv.DragSortListView.DropListener
From interface com.mobeta.android.dslv.DragSortListView.RemoveListener

Public Constructors

public SimpleDragSortCursorAdapter (Context context, int layout, Cursor c, String[] from, int[] to)

This constructor is 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 android.app.LoaderManager with a android.content.CursorLoader.

Constructor the enables auto-requery.

public SimpleDragSortCursorAdapter (Context context, int layout, Cursor c, String[] from, int[] to, int flags)

Standard constructor.

Parameters
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. The layout 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.
flags Flags used to determine the behavior of the adapter, as per CursorAdapter#CursorAdapter(Context, Cursor, int).

Public Methods

public 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. Binding occurs in two phases. First, if a android.widget.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.

Throws
IllegalStateException if binding cannot occur

public void changeCursorAndColumns (Cursor c, String[] from, int[] to)

Change the cursor and change the column-to-view mappings at the same time.

Parameters
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.

public CharSequence convertToString (Cursor cursor)

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().

Parameters
cursor the Cursor to convert to a CharSequence
Returns
  • a non-null CharSequence representing the cursor

public SimpleDragSortCursorAdapter.CursorToStringConverter getCursorToStringConverter ()

Returns the converter used to convert the filtering Cursor into a String.

Returns
  • null if the converter does not exist or an instance of android.widget.SimpleCursorAdapter.CursorToStringConverter
See Also

public int getStringConversionColumn ()

Return the index of the column used to get a String representation of the Cursor.

Returns
  • a valid index in the current Cursor or -1
See Also

public SimpleDragSortCursorAdapter.ViewBinder getViewBinder ()

Returns the SimpleDragSortCursorAdapter.ViewBinder used to bind data to views.

Returns
  • a ViewBinder or null if the binder does not exist
See Also

public void setCursorToStringConverter (SimpleDragSortCursorAdapter.CursorToStringConverter cursorToStringConverter)

Sets the converter used to convert the filtering Cursor into a String.

Parameters
cursorToStringConverter the Cursor to String converter, or null to remove the converter
See Also

public void setStringConversionColumn (int stringConversionColumn)

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.

Parameters
stringConversionColumn a valid index in the current Cursor or -1 to use the default conversion mechanism
See Also

public void setViewBinder (SimpleDragSortCursorAdapter.ViewBinder viewBinder)

Sets the binder used to bind data to views.

Parameters
viewBinder the binder used to bind data to views, can be null to remove the existing binder

public 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. 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.

Parameters
v ImageView to receive an image
value the value retrieved from the cursor

public 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 a TextView. Intended to be overridden by Adapters that need to filter strings retrieved from the database.

Parameters
v TextView to receive text
text the text to be set for the TextView

public Cursor swapCursor (Cursor c)

Swaps Cursor and clears list-Cursor mapping.