Android
android.widget
public class

android.widget.SimpleAdapter

java.lang.Object
android.widget.BaseAdapter ListAdapter SpinnerAdapter
android.widget.SimpleAdapter Filterable

An easy adapter to map static data to views defined in an XML file. You can specify the data backing the list as an ArrayList of Maps. Each entry in the ArrayList corresponds to one row in the list. The Maps contain the data for each row. You also specify an XML file that defines the views used to display the row, and a mapping from keys in the Map to specific views. Binding data to views occurs in two phases. First, if a SimpleAdapter.ViewBinder is available, setViewValue(android.view.View, Object, String) 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, int) or setViewImage(ImageView, String) is invoked. If no appropriate binding can be found, an IllegalStateException is thrown.

Nested Classes
SimpleAdapter.ViewBinder This class can be used by external clients of SimpleAdapter to bind values to views. 

Summary

Constants inherited from interface android.widget.Adapter

Public Constructors

            SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)
Constructor

Public Methods

          int  getCount()
          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)
          long  getItemId(int position)
          View  getView(int position, View convertView, ViewGroup parent)
          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 an TextView.
Methods inherited from class android.widget.BaseAdapter
Methods inherited from class java.lang.Object
Methods inherited from interface android.widget.Adapter
Methods inherited from interface android.widget.Filterable
Methods inherited from interface android.widget.ListAdapter
Methods inherited from interface android.widget.SpinnerAdapter

Details

Public Constructors

public SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)

Constructor

Parameters

context The context where the View associated with this SimpleAdapter is running
data 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 Methods

public int getCount()

See Also

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

public Filter getFilter()

Returns a filter that can be used to constrain data with a filtering pattern.

This method is usually implemented by Adapter classes.

public Object getItem(int position)

See Also

public long getItemId(int position)

See Also

public View getView(int position, View convertView, ViewGroup parent)

public SimpleAdapter.ViewBinder getViewBinder()

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

Returns

  • a ViewBinder or null if the binder does not exist

public void setDropDownViewResource(int resource)

Sets the layout resource to create the drop down views.

Parameters

resource the layout resource defining the drop down views

public void setViewBinder(SimpleAdapter.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

See Also

public 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. This method is called instead of setViewImage(ImageView, String) if the supplied data is an int or Integer.

Parameters

v ImageView to receive an image
value the value retrieved from the data set

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. This method is called instead of setViewImage(ImageView, int) if the supplied data is not an int or Integer.

Parameters

v ImageView to receive an image
value the value retrieved from the data set

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 an TextView.

Parameters

v TextView to receive text
text the text to be set for the TextView
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48