public class SimpleAdapter extends BaseAdapter implements Filterable
SimpleAdapter.ViewBinder
is available,
SimpleAdapter.ViewBinder.setViewValue(android.view.View, Object, String)
is invoked. If the returned value is true, binding has occurred.
If the returned value is false, the following views are then tried in order:
setViewText(TextView, String)
is invoked.
setViewImage(ImageView, int)
or setViewImage(ImageView, String)
is invoked.
IllegalStateException
is thrown.Modifier and Type | Class and Description |
---|---|
static interface |
SimpleAdapter.ViewBinder
This class can be used by external clients of SimpleAdapter to bind
values to views.
|
IGNORE_ITEM_VIEW_TYPE, NO_SELECTION
Constructor and Description |
---|
SimpleAdapter(Context context,
List<? extends Map<String,?>> data,
int resource,
String[] from,
int[] to)
Constructor
|
Modifier and Type | Method and Description |
---|---|
int |
getCount()
How many items are in the data set represented by this Adapter.
|
View |
getDropDownView(int position,
View convertView,
ViewGroup parent)
Get a
View that displays in the drop down popup
the data at the specified position in the data set. |
Filter |
getFilter()
Returns a filter that can be used to constrain data with a filtering
pattern.
|
Object |
getItem(int position)
Get the data item associated with the specified position in the data set.
|
long |
getItemId(int position)
Get the row id associated with the specified position in the list.
|
View |
getView(int position,
View convertView,
ViewGroup parent)
Get a View that displays the data at the specified position in the data set.
|
SimpleAdapter.ViewBinder |
getViewBinder()
Returns the
SimpleAdapter.ViewBinder used to bind data to views. |
void |
setDropDownViewResource(int resource)
Sets the layout resource to create the drop down views.
|
void |
setViewBinder(SimpleAdapter.ViewBinder viewBinder)
Sets the binder used to bind data to views.
|
void |
setViewImage(ImageView v,
int 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 |
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.
|
areAllItemsEnabled, getItemViewType, getViewTypeCount, hasStableIds, isEmpty, isEnabled, notifyDataSetChanged, notifyDataSetInvalidated, registerDataSetObserver, unregisterDataSetObserver
public SimpleAdapter(Context context, List<? extends Map<String,?>> data, int resource, String[] from, int[] to)
context
- The context where the View associated with this SimpleAdapter is runningdata
- A List of Maps. Each entry in the List corresponds to one row in the list. The
Maps contain the data for each row, and should include all the entries specified in
"from"resource
- Resource identifier of a view layout that defines the views for this list
item. The layout file should include at least those named views defined in "to"from
- A list of column names that will be added to the Map associated with each
item.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.public int getCount()
Adapter
getCount
in interface Adapter
Adapter.getCount()
public Object getItem(int position)
Adapter
getItem
in interface Adapter
position
- Position of the item whose data we want within the adapter's
data set.Adapter.getItem(int)
public long getItemId(int position)
Adapter
getItemId
in interface Adapter
position
- The position of the item within the adapter's data set whose row id we want.Adapter.getItemId(int)
public View getView(int position, View convertView, ViewGroup parent)
Adapter
LayoutInflater.inflate(int, android.view.ViewGroup, boolean)
to specify a root view and to prevent attachment to the root.getView
in interface Adapter
position
- The position of the item within the adapter's data set of the item whose view
we want.convertView
- 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 Adapter.getViewTypeCount()
and
Adapter.getItemViewType(int)
).parent
- The parent that this view will eventually be attached toAdapter.getView(int, View, ViewGroup)
public void setDropDownViewResource(int resource)
Sets the layout resource to create the drop down views.
resource
- the layout resource defining the drop down viewsgetDropDownView(int, android.view.View, android.view.ViewGroup)
public View getDropDownView(int position, View convertView, ViewGroup parent)
SpinnerAdapter
Get a View
that displays in the drop down popup
the data at the specified position in the data set.
getDropDownView
in interface SpinnerAdapter
getDropDownView
in class BaseAdapter
position
- index of the item whose view we want.convertView
- 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
- the parent that this view will eventually be attached toView
corresponding to the data at the
specified position.public SimpleAdapter.ViewBinder getViewBinder()
SimpleAdapter.ViewBinder
used to bind data to views.setViewBinder(android.widget.SimpleAdapter.ViewBinder)
public void setViewBinder(SimpleAdapter.ViewBinder viewBinder)
viewBinder
- the binder used to bind data to views, can be null to
remove the existing bindergetViewBinder()
public void setViewImage(ImageView v, int value)
setViewImage(ImageView, String)
if the supplied data is an int or Integer.v
- ImageView to receive an imagevalue
- the value retrieved from the data setsetViewImage(ImageView, String)
public void setViewImage(ImageView v, String value)
setViewImage(ImageView, int)
if the supplied data is not an int or Integer.v
- ImageView to receive an imagevalue
- the value retrieved from the data setsetViewImage(ImageView, int)
public void setViewText(TextView v, String text)
v
- TextView to receive texttext
- the text to be set for the TextViewpublic Filter getFilter()
Filterable
Returns a filter that can be used to constrain data with a filtering pattern.
This method is usually implemented by Adapter
classes.
getFilter
in interface Filterable