Build 1.0_r1(from source)

android.widget
Class ArrayAdapter<T>

java.lang.Object
  extended by android.widget.BaseAdapter
      extended by android.widget.ArrayAdapter<T>
All Implemented Interfaces:
Adapter, Filterable, ListAdapter, SpinnerAdapter

public class ArrayAdapter<T>
extends BaseAdapter
implements Filterable

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.


Field Summary
 
Fields inherited from interface android.widget.Adapter
IGNORE_ITEM_VIEW_TYPE, NO_SELECTION
 
Constructor Summary
ArrayAdapter(Context context, int textViewResourceId)
          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 textViewResourceId, List<T> objects)
          Constructor
ArrayAdapter(Context context, int textViewResourceId, T[] objects)
          Constructor
 
Method Summary
 void add(T object)
          Adds the specified object 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.
 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)
          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.
 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 spcified object at the specified index in the array.
 void notifyDataSetChanged()
          
 void remove(T object)
          Removes the specified object from the array.
 void setDropDownViewResource(int resource)
          Sets the layout resource to create the drop down views.
 void setNotifyOnChange(boolean notifyOnChange)
          Control whether methods that change the list (add(T), insert(T, int), remove(T), clear()) automatically call notifyDataSetChanged().
 
Methods inherited from class android.widget.BaseAdapter
areAllItemsEnabled, getItemViewType, getViewTypeCount, hasStableIds, isEmpty, isEnabled, notifyDataSetInvalidated, registerDataSetObserver, unregisterDataSetObserver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayAdapter

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.

ArrayAdapter

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

ArrayAdapter

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.

ArrayAdapter

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.

ArrayAdapter

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.

ArrayAdapter

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.
Method Detail

add

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.

insert

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.

remove

public void remove(T object)
Removes the specified object from the array.

Parameters:
object - The object to remove.

clear

public void clear()
Remove all elements from the list.


notifyDataSetChanged

public void notifyDataSetChanged()

Overrides:
notifyDataSetChanged in class BaseAdapter

setNotifyOnChange

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.

Parameters:
notifyOnChange - if true, modifications to the list will automatically call notifyDataSetChanged()

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.

Returns:
The Context associated with this adapter.

getCount

public int getCount()
How many items are in the data set represented by this Adapter.

Specified by:
getCount in interface Adapter
Returns:
Count of items.

getItem

public T getItem(int position)
Get the data item associated with the specified position in the data set.

Specified by:
getItem in interface Adapter
Parameters:
position - Position of the item whose data we want within the adapter's data set.
Returns:
The data at the specified position.

getPosition

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.

getItemId

public long getItemId(int position)
Get the row id associated with the specified position in the list.

Specified by:
getItemId in interface Adapter
Parameters:
position - The position of the item within the adapter's data set whose row id we want.
Returns:
The id of the item at the specified position.

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.

Specified by:
getView in interface Adapter
Parameters:
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.
parent - The parent that this view will eventually be attached to
Returns:
A View corresponding to the data at the specified position.

setDropDownViewResource

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
See Also:
getDropDownView(int, android.view.View, android.view.ViewGroup)

getDropDownView

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.

Specified by:
getDropDownView in interface SpinnerAdapter
Overrides:
getDropDownView in class BaseAdapter
Parameters:
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 to
Returns:
a View corresponding to the data at the specified position.

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

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.
Returns:
An ArrayAdapter.

getFilter

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.

Specified by:
getFilter in interface Filterable
Returns:
a filter used to constrain data

Build 1.0_r1(from source)

Please submit a feedback, bug or feature