> Documentation index: https://developer.android.com/reference/llms.txt

Summary: [Inherited Constants](https://developer.android.com/reference/android/widget/ArrayAdapter.md.txt#inhconstants) \| [Ctors](https://developer.android.com/reference/android/widget/ArrayAdapter.md.txt#pubctors) \| [Methods](https://developer.android.com/reference/android/widget/ArrayAdapter.md.txt#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/widget/ArrayAdapter.md.txt#inhmethods)

# ArrayAdapter

*** ** * ** ***


`
public


class
ArrayAdapter
`


`


`

`

extends BaseAdapter


`

`


implements

Filterable,

ThemedSpinnerAdapter


`

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.md.txt) |||
| ↳ | [android.widget.BaseAdapter](https://developer.android.com/reference/android/widget/BaseAdapter.md.txt) ||
|   | ↳ | android.widget.ArrayAdapter\<T\> |

<br />

*** ** * ** ***

You can use this adapter to provide views for an `AdapterView`,
Returns a view for each object in a collection of data objects you
provide, and can be used with list-based user interface widgets such as
`ListView` or `Spinner`.


By default, the array adapter creates a view by calling `Object.toString()` on each
data object in the collection you provide, and places the result in a TextView.
You may also customize what type of view is used for the data object in the collection.
To customize what type of view is used for the data object,
override `getView(int,View,ViewGroup)`
and inflate a view resource.


For an example of using an array adapter with a ListView, see the
[Adapter Views](https://developer.android.com/guide/topics/ui/declaring-layout#AdapterViews) guide.


For an example of using an array adapter with a Spinner, see the
[Spinners](https://developer.android.com/guide/topics/ui/controls/spinner) guide.

**Note:**
If you are considering using array adapter with a ListView, consider using
`RecyclerView` instead.
RecyclerView offers similar features with better performance and more flexibility than
ListView provides.
See the
[Recycler View](https://developer.android.com/guide/topics/ui/layout/recyclerview.html) guide.

<br />

## Summary

### Inherited constants

From interface `android.widget.Adapter` `int` `IGNORE_ITEM_VIEW_TYPE`

An item view type that causes the `AdapterView` to ignore the item
view.


`int` `NO_SELECTION`


| ### Public constructors ||
|---|---|
| ` ArrayAdapter(Context context, int resource) ` Constructor |
| ` ArrayAdapter(Context context, int resource, int textViewResourceId) ` Constructor |
| ` ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects) ` Constructor |
| ` ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects) ` Constructor. |
| ` ArrayAdapter(Context context, int resource, List<T> objects) ` Constructor |
| ` ArrayAdapter(Context context, int resource, T[] objects) ` Constructor. |

| ### Public methods ||
|---|---|
| ` void` | ` add(T object) ` Adds the specified object at the end of the array. |
| ` void` | ` addAll(Collection<? extends T> collection) ` Adds the specified Collection at the end of the array. |
| ` void` | ` addAll(T... items) ` Adds the specified items at the end of the array. |
| ` void` | ` clear() ` Remove all elements from the list. |
| ` static ArrayAdapter<CharSequence>` | ` createFromResource(Context context, int textArrayResId, int textViewResId) ` Creates a new ArrayAdapter from external resources. |
| ` CharSequence[]` | ` getAutofillOptions() ` Gets a string representation of the adapter data that can help `AutofillService` autofill the view backed by the adapter. |
| ` Context` | ` getContext() ` Returns the context associated with this array adapter. |
| ` int` | ` getCount() ` How many items are in the data set represented by this Adapter. |
| ` View` | ` getDropDownView(int position, View convertView, ViewGroup parent) ` Gets a `View` that displays in the drop down popup the data at the specified position in the data set. |
| ` Resources.Theme` | ` getDropDownViewTheme() ` Returns the value previously set by a call to `setDropDownViewTheme(Theme)`. |
| ` Filter` | ` getFilter() ` <br /> Returns a filter that can be used to constrain data with a filtering pattern. |
| ` T` | ` 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. |
| ` int` | ` getPosition(T item) ` Returns the position of the specified item in the array. |
| ` View` | ` getView(int position, View convertView, ViewGroup parent) ` Get a View that displays the data at the specified position in the data set. |
| ` void` | ` insert(T object, int index) ` Inserts the specified object at the specified index in the array. |
| ` void` | ` notifyDataSetChanged() ` Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself. |
| ` void` | ` remove(T object) ` Removes the specified object from the array. |
| ` void` | ` setDropDownViewResource(int resource) ` <br /> Sets the layout resource to create the drop down views. |
| ` void` | ` setDropDownViewTheme(Resources.Theme theme) ` Sets the `Resources.Theme` against which drop-down views are inflated. |
| ` void` | ` setNotifyOnChange(boolean notifyOnChange) ` Control whether methods that change the list (`add(T)`, `addAll(Collection)`, `addAll(Object[])`, `insert(T, int)`, `remove(T)`, `clear()`, `sort(Comparator)`) automatically call `notifyDataSetChanged()`. |
| ` void` | ` sort(Comparator<? super T> comparator) ` Sorts the content of this adapter using the specified comparator. |

### Inherited methods

From class `

android.widget.BaseAdapter

` `


boolean` `
areAllItemsEnabled()
`

Indicates whether all the items in this adapter are enabled.


`


CharSequence[]` `
getAutofillOptions()
`

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


`


View` `
getDropDownView(int position, View convertView, ViewGroup parent)
`

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


`


int` `
getItemViewType(int position)
`

Get the type of View that will be created by `getView(int, View, ViewGroup)` for the specified item.


`


int` `
getViewTypeCount()
`

<br />


Returns the number of types of Views that will be created by
`getView(int, View, ViewGroup)`.


`


boolean` `
hasStableIds()
`

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


`


boolean` `
isEmpty()
`


`


boolean` `
isEnabled(int position)
`

Returns true if the item at the specified position is not a separator.


`


void` `
notifyDataSetChanged()
`

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


`


void` `
notifyDataSetInvalidated()
`

Notifies the attached observers that the underlying data is no longer valid
or available.


`


void` `
registerDataSetObserver(DataSetObserver observer)
`

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


`


void` `
setAutofillOptions(CharSequence... options)
`

Sets the value returned by `getAutofillOptions()`


`


void` `
unregisterDataSetObserver(DataSetObserver observer)
`

Unregister an observer that has previously been registered with this
adapter via `registerDataSetObserver(DataSetObserver)`.


From class `

java.lang.Object

` `


Object` `
clone()
`

Creates and returns a copy of this object.


`


boolean` `
equals(Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
finalize()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

Class<?>` `
getClass()
`

Returns the runtime class of this `Object`.


`


int` `
hashCode()
`

Returns a hash code value for the object.


`


final

void` `
notify()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
notifyAll()
`

Wakes up all threads that are waiting on this object's monitor.


`


String` `
toString()
`

Returns a string representation of the object.


`


final

void` `
wait(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
wait(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
wait()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


From interface `

android.widget.ListAdapter

` `
abstract


boolean` `
areAllItemsEnabled()
`

Indicates whether all the items in this adapter are enabled.


`
abstract


boolean` `
isEnabled(int position)
`

Returns true if the item at the specified position is not a separator.


From interface `

android.widget.SpinnerAdapter

` `
abstract


View` `
getDropDownView(int position, View convertView, ViewGroup parent)
`

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


From interface `

android.widget.Filterable

` `
abstract


Filter` `
getFilter()
`

<br />

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


From interface `

android.widget.ThemedSpinnerAdapter

` `
abstract


Resources.Theme` `
getDropDownViewTheme()
`

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


`
abstract


void` `
setDropDownViewTheme(Resources.Theme theme)
`

Sets the `Resources.Theme` against which drop-down views are
inflated.


From interface `

android.widget.Adapter

` `

default


CharSequence[]` `
getAutofillOptions()
`

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


`
abstract


int` `
getCount()
`

How many items are in the data set represented by this Adapter.


`
abstract


Object` `
getItem(int position)
`

Get the data item associated with the specified position in the data set.


`
abstract


long` `
getItemId(int position)
`

Get the row id associated with the specified position in the list.


`
abstract


int` `
getItemViewType(int position)
`

Get the type of View that will be created by `getView(int, View, ViewGroup)` for the specified item.


`
abstract


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

Get a View that displays the data at the specified position in the data set.


`
abstract


int` `
getViewTypeCount()
`

<br />


Returns the number of types of Views that will be created by
`getView(int, View, ViewGroup)`.


`
abstract


boolean` `
hasStableIds()
`

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


`
abstract


boolean` `
isEmpty()
` `
abstract


void` `
registerDataSetObserver(DataSetObserver observer)
`

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


`
abstract


void` `
unregisterDataSetObserver(DataSetObserver observer)
`

Unregister an observer that has previously been registered with this
adapter via `registerDataSetObserver(DataSetObserver)`.


## Public constructors

### ArrayAdapter

```
public ArrayAdapter (Context context, 
                int resource)
```

Constructor

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The current context. This value cannot be `null`. <br /> |
| `resource` | `int`: The resource ID for a layout file containing a TextView to use when instantiating views. <br /> |

### ArrayAdapter

```
public ArrayAdapter (Context context, 
                int resource, 
                int textViewResourceId)
```

Constructor

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The current context. This value cannot be `null`. <br /> |
| `resource` | `int`: The resource ID for a layout file containing a layout to use when instantiating views. <br /> |
| `textViewResourceId` | `int`: The id of the TextView within the layout resource to be populated <br /> |

### ArrayAdapter

```
public ArrayAdapter (Context context, 
                int resource, 
                int textViewResourceId, 
                List<T> objects)
```

Constructor

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The current context. This value cannot be `null`. <br /> |
| `resource` | `int`: The resource ID for a layout file containing a layout to use when instantiating views. <br /> |
| `textViewResourceId` | `int`: The id of the TextView within the layout resource to be populated <br /> |
| `objects` | `List`: The objects to represent in the ListView. This value cannot be `null`. <br /> |

### ArrayAdapter

```
public ArrayAdapter (Context context, 
                int resource, 
                int textViewResourceId, 
                T[] objects)
```

Constructor. This constructor will result in the underlying data collection being
immutable, so methods such as `clear()` will throw an exception.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The current context. This value cannot be `null`. <br /> |
| `resource` | `int`: The resource ID for a layout file containing a layout to use when instantiating views. <br /> |
| `textViewResourceId` | `int`: The id of the TextView within the layout resource to be populated <br /> |
| `objects` | `T`: The objects to represent in the ListView. This value cannot be `null`. <br /> |

### ArrayAdapter

```
public ArrayAdapter (Context context, 
                int resource, 
                List<T> objects)
```

Constructor

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The current context. This value cannot be `null`. <br /> |
| `resource` | `int`: The resource ID for a layout file containing a TextView to use when instantiating views. <br /> |
| `objects` | `List`: The objects to represent in the ListView. This value cannot be `null`. <br /> |

### ArrayAdapter

```
public ArrayAdapter (Context context, 
                int resource, 
                T[] objects)
```

Constructor. This constructor will result in the underlying data collection being
immutable, so methods such as `clear()` will throw an exception.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The current context. This value cannot be `null`. <br /> |
| `resource` | `int`: The resource ID for a layout file containing a TextView to use when instantiating views. <br /> |
| `objects` | `T`: The objects to represent in the ListView. This value cannot be `null`. <br /> |

## Public methods

### add

```
public void add (T object)
```

Adds the specified object at the end of the array.

<br />

| Parameters ||
|---|---|
| `object` | `T`: The object to add at the end of the array. This value may be `null`. <br /> |

| Throws ||
|---|---|
| `UnsupportedOperationException` | if the underlying data collection is immutable |

### addAll

```
public void addAll (Collection<? extends T> collection)
```

Adds the specified Collection at the end of the array.

<br />

| Parameters ||
|---|---|
| `collection` | `Collection`: The Collection to add at the end of the array. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `ClassCastException` | if the class of an element of the specified collection prevents it from being added to this list |
| `IllegalArgumentException` | if some property of an element of the specified collection prevents it from being added to this list |
| `NullPointerException` | if the specified collection contains one or more null elements and this list does not permit null elements, or if the specified collection is null |
| `UnsupportedOperationException` | if the addAll operation is not supported by this list |

### addAll

```
public void addAll (T... items)
```

Adds the specified items at the end of the array.

<br />

| Parameters ||
|---|---|
| `items` | `T`: The items to add at the end of the array. <br /> |

| Throws ||
|---|---|
| `UnsupportedOperationException` | if the underlying data collection is immutable |

### clear

```
public void clear ()
```

Remove all elements from the list.

<br />

| Throws ||
|---|---|
| `UnsupportedOperationException` | if the underlying data collection is immutable |

### createFromResource

```
public static ArrayAdapter<CharSequence> createFromResource (Context context, 
                int textArrayResId, 
                int textViewResId)
```

Creates a new ArrayAdapter from external resources. The content of the array is
obtained through `Resources.getTextArray(int)`.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The application's environment. This value cannot be `null`. <br /> |
| `textArrayResId` | `int`: The identifier of the array to use as the data source. <br /> |
| `textViewResId` | `int`: The identifier of the layout used to create views. <br /> |

| Returns ||
|---|---|
| `ArrayAdapter<CharSequence>` | An ArrayAdapter. This value cannot be `null`. <br /> |

### getAutofillOptions

```
public CharSequence[] getAutofillOptions ()
```

Gets a string representation of the adapter data that can help
`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
`ViewStructure.setDataIsSensitive(boolean)` for more info.

<br />

| Returns ||
|---|---|
| `CharSequence[]` | values from the string array used by `createFromResource(Context,int,int)`, or `null` if object was created otherwsie or if contents were dynamically changed after creation. <br /> |

### getContext

```
public Context getContext ()
```

Returns the context associated with this array adapter. The context is used
to create views from the resource passed to the constructor.

<br />

| Returns ||
|---|---|
| `Context` | The Context associated with this adapter. This value cannot be `null`. <br /> |

### getCount

```
public int getCount ()
```

How many items are in the data set represented by this Adapter.

<br />

| Returns ||
|---|---|
| `int` | Count of items. <br /> |

### getDropDownView

```
public View getDropDownView (int position, 
                View convertView, 
                ViewGroup parent)
```

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

<br />

| Parameters ||
|---|---|
| `position` | `int`: index of the item whose view we want. <br /> |
| `convertView` | `View`: This value may be `null`. <br /> |
| `parent` | `ViewGroup`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `View` | a `View` corresponding to the data at the specified position. <br /> |

### getDropDownViewTheme

```
public Resources.Theme getDropDownViewTheme ()
```

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

<br />

| Returns ||
|---|---|
| `Resources.Theme` | This value may be `null`. <br /> |

### getFilter

```
public Filter getFilter ()
```

<br />

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

This method is usually implemented by `Adapter`
classes.

<br />

<br />

| Returns ||
|---|---|
| `Filter` | This value cannot be `null`. <br /> |

### getItem

```
public T getItem (int position)
```

Get the data item associated with the specified position in the data set.

<br />

| Parameters ||
|---|---|
| `position` | `int`: Position of the item whose data we want within the adapter's data set. <br /> |

| Returns ||
|---|---|
| `T` | This value may be `null`. <br /> |

### getItemId

```
public long getItemId (int position)
```

Get the row id associated with the specified position in the list.

<br />

| Parameters ||
|---|---|
| `position` | `int`: The position of the item within the adapter's data set whose row id we want. <br /> |

| Returns ||
|---|---|
| `long` | The id of the item at the specified position. <br /> |

### getPosition

```
public int getPosition (T item)
```

Returns the position of the specified item in the array.

<br />

| Parameters ||
|---|---|
| `item` | `T`: The item to retrieve the position of. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `int` | The position of the specified item. <br /> |

### getView

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

Get a View that displays the data at the specified position in the data set. You can either
create a View manually or inflate it from an XML layout file. When the View is inflated, the
parent View (GridView, ListView...) will apply default layout parameters unless you use
`LayoutInflater.inflate(int, android.view.ViewGroup, boolean)`
to specify a root view and to prevent attachment to the root.

<br />

| Parameters ||
|---|---|
| `position` | `int`: The position of the item within the adapter's data set of the item whose view we want. <br /> |
| `convertView` | `View`: This value may be `null`. <br /> |
| `parent` | `ViewGroup`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `View` | This value cannot be `null`. <br /> |

### insert

```
public void insert (T object, 
                int index)
```

Inserts the specified object at the specified index in the array.

<br />

| Parameters ||
|---|---|
| `object` | `T`: The object to insert into the array. This value may be `null`. <br /> |
| `index` | `int`: The index at which the object must be inserted. <br /> |

| Throws ||
|---|---|
| `UnsupportedOperationException` | if the underlying data collection is immutable |

### notifyDataSetChanged

```
public void notifyDataSetChanged ()
```

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

<br />

### remove

```
public void remove (T object)
```

Removes the specified object from the array.

<br />

| Parameters ||
|---|---|
| `object` | `T`: The object to remove. This value may be `null`. <br /> |

| Throws ||
|---|---|
| `UnsupportedOperationException` | if the underlying data collection is immutable |

### setDropDownViewResource

```
public void setDropDownViewResource (int resource)
```

<br />

Sets the layout resource to create the drop down views.

<br />

<br />

| Parameters ||
|---|---|
| `resource` | `int`: the layout resource defining the drop down views <br /> |

**See also:**

- `getDropDownView(int, android.view.View, android.view.ViewGroup)`

### setDropDownViewTheme

```
public void setDropDownViewTheme (Resources.Theme theme)
```

Sets the `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.

<br />

| Parameters ||
|---|---|
| `theme` | `Resources.Theme`: the theme against which to inflate drop-down views or `null` to use the theme from the adapter's context <br /> |

**See also:**

- `getDropDownView(int,View,ViewGroup)`

### setNotifyOnChange

```
public void setNotifyOnChange (boolean notifyOnChange)
```

Control whether methods that change the list (`add(T)`, `addAll(Collection)`,
`addAll(Object[])`, `insert(T, int)`, `remove(T)`, `clear()`,
`sort(Comparator)`) automatically call `notifyDataSetChanged()`. If set to
false, caller must manually call notifyDataSetChanged() to have the changes
reflected in the attached view.

The default is true, and calling notifyDataSetChanged()
resets the flag to true.

<br />

| Parameters ||
|---|---|
| `notifyOnChange` | `boolean`: if true, modifications to the list will automatically call `notifyDataSetChanged()` <br /> |

### sort

```
public void sort (Comparator<? super T> comparator)
```

Sorts the content of this adapter using the specified comparator.

<br />

| Parameters ||
|---|---|
| `comparator` | `Comparator`: The comparator used to sort the objects contained in this adapter. This value cannot be `null`. <br /> |