android.widget.ArrayAdapter<T>
A ListAdapter that manages a ListView backed by an array of arbitrary
objects. By default this class expects that the provided resource id referecnes
a single TextView. If you want to use a more complex layout, use the constructors that
also takes a field id. That field id should reference a TextView in the larger layout
resource.
However the TextView is referenced, it will be filled with the toString() of each object in
the array. You can add lists or arrays of custom objects. Override the toString() method
of your objects to determine what text will be displayed for the item in the list.
To use something other than TextViews for the array display, for instance, ImageViews,
or to have some of data besides toString() results fill the views,
override getView(int, View, ViewGroup) to return the type of view you want.
Summary
Public Constructors
|
|
|
|
|
|
ArrayAdapter(Context context, int textViewResourceId) |
|
|
|
|
|
|
ArrayAdapter(Context context, int resource, int textViewResourceId) |
|
|
|
|
|
|
ArrayAdapter(Context context, int textViewResourceId, T[] objects) |
|
|
|
|
|
|
ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects) |
|
|
|
|
|
|
ArrayAdapter(Context context, int textViewResourceId, List<T> objects) |
|
|
|
|
|
|
ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects) |
Public Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Public Constructors
public
ArrayAdapter(Context context, int textViewResourceId)
Constructor
Parameters
context
| The current context. |
textViewResourceId
| The resource ID for a layout file containing a TextView to use when
instantiating views.
|
public
ArrayAdapter(Context context, int resource, int textViewResourceId)
Constructor
Parameters
context
| The current context. |
resource
| The resource ID for a layout file containing a layout to use when
instantiating views. |
textViewResourceId
| The id of the TextView within the layout resource to be populated
|
public
ArrayAdapter(Context context, int textViewResourceId, T[] objects)
Constructor
Parameters
context
| The current context. |
textViewResourceId
| The resource ID for a layout file containing a TextView to use when
instantiating views. |
objects
| The objects to represent in the ListView.
|
public
ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)
Constructor
Parameters
context
| The current context. |
resource
| The resource ID for a layout file containing a layout to use when
instantiating views. |
textViewResourceId
| The id of the TextView within the layout resource to be populated |
objects
| The objects to represent in the ListView.
|
public
ArrayAdapter(Context context, int textViewResourceId, List<T> objects)
Constructor
Parameters
context
| The current context. |
textViewResourceId
| The resource ID for a layout file containing a TextView to use when
instantiating views. |
objects
| The objects to represent in the ListView.
|
public
ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects)
Constructor
Parameters
context
| The current context. |
resource
| The resource ID for a layout file containing a layout to use when
instantiating views. |
textViewResourceId
| The id of the TextView within the layout resource to be populated |
objects
| The objects to represent in the ListView.
|
Public Methods
public
void
add(T object)
Adds the specified object at the end of the array.
Parameters
object
| The object to add at the end of the array.
|
public
void
clear()
Remove all elements from the list.
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
getTextArray(int).
Parameters
context
| The application's environment. |
textArrayResId
| The identifier of the array to use as the data source. |
textViewResId
| The identifier of the layout used to create views. |
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.
Returns
- The Context associated with this adapter.
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
T
getItem(int position)
public
long
getItemId(int position)
public
int
getPosition(T item)
Returns the position of the specified item in the array.
Parameters
item
| The item to retrieve the position of. |
Returns
- The position of the specified item.
public
void
insert(T object, int index)
Inserts the spcified object at the specified index in the array.
Parameters
object
| The object to insert into the array. |
index
| The index at which the object must be inserted.
|
public
void
notifyDataSetChanged()
public
void
remove(T object)
Removes the specified object from the array.
Parameters
object
| The object to remove.
|
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
setNotifyOnChange(boolean notifyOnChange)
Control whether methods that change the list (
add(T),
insert(T, int),
remove(T),
clear()) 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.