open class SimpleAdapter : BaseAdapter, Filterable, ThemedSpinnerAdapter

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 android.widget.SimpleAdapter.ViewBinder is available, 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:

If no appropriate binding can be found, an IllegalStateException is thrown.

Summary

Nested classes
abstract

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

Public constructors

SimpleAdapter(context: Context!, data: MutableList<out MutableMap<String!, *>!>!, resource: Int, from: Array<String!>!, to: IntArray!)

Constructor

Public methods
open Int

getCount()

open View!

getDropDownView(position: Int, convertView: View!, parent: ViewGroup!)

Gets a android.view.View that displays in the drop down popup the data at the specified position in the data set.

open Resources.Theme?

Returns the value previously set by a call to setDropDownViewTheme(Theme).

open Filter!

getFilter()

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

open Any!

getItem(position: Int)

open Long

getItemId(position: Int)

open View!

getView(position: Int, convertView: View!, parent: ViewGroup!)

open SimpleAdapter.ViewBinder!

Returns the ViewBinder used to bind data to views.

open Unit

Sets the layout resource to create the drop down views.

open Unit

Sets the android.content.res.Resources.Theme against which drop-down views are inflated.

open Unit

Sets the binder used to bind data to views.

open Unit

setViewImage(v: ImageView!, value: Int)

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.

open Unit

setViewImage(v: ImageView!, value: String!)

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.

open Unit

setViewText(v: TextView!, text: String!)

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.

Inherited functions

From class BaseAdapter

Boolean areAllItemsEnabled()

Indicates whether all the items in this adapter are enabled. If the value returned by this method changes over time, there is no guarantee it will take effect. If true, it means all items are selectable and clickable (there is no separator.)

Array<CharSequence!>? getAutofillOptions()

Gets a string representation of the adapter data that can help android.service.autofill.AutofillService autofill the view backed by the adapter.

It should only be set (i.e., non-null if the values do not represent PII (Personally Identifiable Information - sensitive data such as email addresses, credit card numbers, passwords, etc...). For example, it's ok to return a list of month names, but not a list of usernames. A good rule of thumb is that if the adapter data comes from static resources, such data is not PII - see android.view.ViewStructure#setDataIsSensitive(boolean) for more info.

Int getItemViewType(position: Int)

Get the type of View that will be created by getView for the specified item.

Int getViewTypeCount()

Returns the number of types of Views that will be created by getView. Each type represents a set of views that can be converted in getView. If the adapter always returns the same type of View for all items, this method should return 1.

This method will only be called when the adapter is set on the AdapterView.

Boolean hasStableIds()

Indicates whether the item ids are stable across changes to the underlying data.

Boolean isEmpty()
Boolean isEnabled(position: Int)

Returns true if the item at the specified position is not a separator. (A separator is a non-selectable, non-clickable item). The result is unspecified if position is invalid. An ArrayIndexOutOfBoundsException should be thrown in that case for fast failure.

Unit notifyDataSetChanged()

Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself.

Unit notifyDataSetInvalidated()

Notifies the attached observers that the underlying data is no longer valid or available. Once invoked this adapter is no longer valid and should not report further data set changes.

Unit registerDataSetObserver(observer: DataSetObserver!)

Register an observer that is called when changes happen to the data used by this adapter.

Unit setAutofillOptions(vararg options: CharSequence!)

Sets the value returned by getAutofillOptions()

Unit unregisterDataSetObserver(observer: DataSetObserver!)

Unregister an observer that has previously been registered with this adapter via registerDataSetObserver.

Public constructors

SimpleAdapter

SimpleAdapter(
    context: Context!,
    data: MutableList<out MutableMap<String!, *>!>!,
    resource: Int,
    from: Array<String!>!,
    to: IntArray!)

Constructor

Parameters
context Context!: The context where the View associated with this SimpleAdapter is running
data MutableList<out MutableMap<String!, *>!>!: 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 Int: 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 Array<String!>!: A list of column names that will be added to the Map associated with each item.
to IntArray!: 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

getCount

open fun getCount(): Int
Return
Int Count of items.

getDropDownView

open fun getDropDownView(
    position: Int,
    convertView: View!,
    parent: ViewGroup!
): View!

Gets a android.view.View that displays in the drop down popup the data at the specified position in the data set.

Parameters
position Int: index of the item whose view we want.
convertView View!: 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 ViewGroup!: the parent that this view will eventually be attached to
Return
View! a android.view.View corresponding to the data at the specified position.

getFilter

open fun getFilter(): Filter!

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

This method is usually implemented by android.widget.Adapter classes.

Return
Filter! a filter used to constrain data

getItem

open fun getItem(position: Int): Any!
Parameters
position Int: Position of the item whose data we want within the adapter's data set.
Return
Any! The data at the specified position.

getItemId

open fun getItemId(position: Int): Long
Parameters
position Int: The position of the item within the adapter's data set whose row id we want.
Return
Long The id of the item at the specified position.

getView

open fun getView(
    position: Int,
    convertView: View!,
    parent: ViewGroup!
): View!
Parameters
position Int: The position of the item within the adapter's data set of the item whose view we want.
convertView View!: 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 getViewTypeCount() and getItemViewType(int)).
parent ViewGroup!: The parent that this view will eventually be attached to
Return
View! A View corresponding to the data at the specified position.

setDropDownViewResource

open fun setDropDownViewResource(resource: Int): Unit

Sets the layout resource to create the drop down views.

Parameters
resource Int: the layout resource defining the drop down views

setDropDownViewTheme

open fun setDropDownViewTheme(theme: Resources.Theme?): Unit

Sets the android.content.res.Resources.Theme against which drop-down views are inflated.

By default, drop-down views are inflated against the theme of the Context passed to the adapter's constructor.

Parameters
theme Resources.Theme?: the theme against which to inflate drop-down views or null to use the theme from the adapter's context

setViewImage

open fun setViewImage(
    v: ImageView!,
    value: Int
): Unit

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!: ImageView to receive an image
value Int: the value retrieved from the data set

setViewImage

open fun setViewImage(
    v: ImageView!,
    value: String!
): Unit

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!: ImageView to receive an image
value String!: the value retrieved from the data set

setViewText

open fun setViewText(
    v: TextView!,
    text: String!
): Unit

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.

Parameters
v TextView!: TextView to receive text
text String!: the text to be set for the TextView

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-02-26 UTC.