Constants
public static final int IGNORE_ITEM_VIEW_TYPE
Since: API Level 1An item view type that causes the
AdapterView
to ignore the item view. For example, this can be used if the client
does not want a particular view to be given for conversion in
getView(int,
View, ViewGroup)
.See Also
Constant Value: -1 (0xffffffff)public static final int NO_SELECTION
Since: API Level 1Constant Value: -2147483648 (0x80000000)
Public Methods
public abstract int getCount ()
Since: API Level 1How many items are in the data set represented by this Adapter.
Returns
- Count of items.
public abstract Object getItem (int position)
Since: API Level 1Get the data item associated with the specified position in the data set.
Parameters
position | Position of the item whose data we want within the adapter's data set. |
---|
Returns
- The data at the specified position.
public abstract long getItemId (int position)
Since: API Level 1Get the row id associated with the specified position in the list.
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.
public abstract int getItemViewType (int position)
Since: API Level 1Get the type of View that will be created by
getView(int,
View, ViewGroup)
for the specified item.Parameters
position | The position of the item within the adapter's data set whose view type we want. |
---|
Returns
- An integer representing the type of View. Two views should
share the same type if one can be converted to the other in
getView(int, View, ViewGroup)
. Note: Integers must be in the range 0 togetViewTypeCount()
- 1.IGNORE_ITEM_VIEW_TYPE
can also be returned.
See Also
public abstract View getView (int position, View convertView, ViewGroup parent)
Since: API Level 1Get 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
inflate(int,
android.view.ViewGroup, boolean)
to specify a root view
and to prevent attachment to the root.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. 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 | The parent that this view will eventually be attached to |
Returns
- A View corresponding to the data at the specified position.
public abstract int getViewTypeCount ()
Since: API Level 1Returns the number of types of Views that will be created by
getView(int,
View, ViewGroup)
. Each type represents a set of views that
can be converted in getView(int,
View, ViewGroup)
. 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 when the adapter is set on the the
AdapterView
.
Returns
- The number of types of Views that will be created by this
adapter
public abstract boolean hasStableIds ()
Since: API Level 1Indicates whether the item ids are stable across changes to the underlying data.
Returns
- True if the same id always refers to the same object.
public abstract boolean isEmpty ()
Since: API Level 1Returns
- true if this adapter doesn't contain any data. This is used
to determine whether the empty view should be displayed. A typical
implementation will return getCount() == 0 but since getCount()
includes the headers and footers, specialized adapters might want a
different behavior.
public abstract void registerDataSetObserver (DataSetObserver observer)
Since: API Level 1Register an observer that is called when changes happen to the data used by this adapter.
Parameters
observer | the object that gets notified when the data set changes. |
---|
public abstract void unregisterDataSetObserver (DataSetObserver observer)
Since: API Level 1Unregister an observer that has previously been registered with this adapter via
registerDataSetObserver(DataSetObserver)
.Parameters
observer | the object to unregister. |
---|
a)
ArrayAdapters
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.
Public Constructors
public ArrayAdapter (Context context, int textViewResourceId)
Since: API Level 1Constructor
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)
Since: API Level 1Constructor
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)
Since: API Level 1Constructor
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)
Since: API Level 1Constructor
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)
Since: API Level 1Constructor
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)
Since: API Level 1Constructor
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)
Since: API Level 1Adds the specified object at the end of the array.
Parameters
object | The object to add at the end of the array. |
---|
public void addAll (Collection<? extends T> collection)
Since: API Level 11Adds the specified Collection at the end of the array.
Parameters
collection | The Collection to add at the end of the array. |
---|
public void addAll (T... items)
Since: API Level 11Adds the specified items at the end of the array.
Parameters
items | The items to add at the end of the array. |
---|
public void clear ()
Since: API Level 1Remove all elements from the list.
public static ArrayAdapter<CharSequence> createFromResource (Context context, int textArrayResId, int textViewResId)
Since: API Level 1Creates 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. |
Returns
- An ArrayAdapter.
public Context getContext ()
Since: API Level 1Returns 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 int getCount ()
Since: API Level 1public View getDropDownView (int position, View convertView, ViewGroup parent)
Since: API Level 1Get a
View
that displays in the drop down popup the data at the specified
position in the data set.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.
public Filter getFilter ()
Since: API Level 1Returns a filter that can be used to constrain data with a filtering pattern.
This method is usually implemented by
Adapter
classes.Returns
- a filter used to constrain data
public T getItem (int position)
Since: API Level 1public long getItemId (int position)
Since: API Level 1public int getPosition (T item)
Since: API Level 1Returns 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 View getView (int position, View convertView, ViewGroup parent)
Since: API Level 1public void insert (T object, int index)
Since: API Level 1Inserts the specified 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 ()
Since: API Level 1Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself.
public void remove (T object)
Since: API Level 1Removes the specified object from the array.
Parameters
object | The object to remove. |
---|
public void setDropDownViewResource (int resource)
Since: API Level 1Sets the layout resource to create the drop down views.
Parameters
resource | the layout resource defining the drop down views |
---|
See Also
public void setNotifyOnChange (boolean notifyOnChange)
Since: API Level 1Control 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()
|
---|
public void sort (Comparator<? super T> comparator)
Since: API Level 3Sorts the content of this adapter using the specified comparator.
Parameters
comparator | The comparator used to sort the objects contained in this adapter. |
---|
b)
BaseAdapters
Common base class of common implementation for an
Adapter
that can be used in both ListView
(by implementing the specialized ListAdapter
interface} and Spinner
(by implementing the specialized SpinnerAdapter
interface.
Public Constructors
public BaseAdapter ()
Since: API Level 1Public Methods
public boolean areAllItemsEnabled ()
Since: API Level 1Indicates 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.)
Returns
- True if all items are enabled, false otherwise.
public View getDropDownView (int position, View convertView, ViewGroup parent)
Since: API Level 1Get a
View
that displays in the drop down popup the data at the specified
position in the data set.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.
public int getItemViewType (int position)
Since: API Level 1Get the type of View that will be created by
getView(int,
View, ViewGroup)
for the specified item.Parameters
position
|
The position of the item within the adapter's data set whose
view type we want. |
---|
Returns
- An integer representing the type of View. Two views should
share the same type if one can be converted to the other in
getView(int, View, ViewGroup)
. Note: Integers must be in the range 0 togetViewTypeCount()
- 1.IGNORE_ITEM_VIEW_TYPE
can also be returned.
public int getViewTypeCount ()
Since: API Level 1Returns the number of types of Views that will be created by
getView(int,
View, ViewGroup)
. Each type represents a set of views that
can be converted in getView(int,
View, ViewGroup)
. 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 when the adapter is set on the the
AdapterView
.
Returns
- The number of types of Views that will be created by this
adapter
public boolean hasStableIds ()
Since: API Level 1Indicates whether the item ids are stable across changes to the underlying data.
Returns
- True if the same id always refers to the same object.
public boolean isEmpty ()
Since: API Level 1public boolean isEnabled (int position)
Since: API Level 1Returns 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.Parameters
position
|
Index of the item |
---|
Returns
- True if the item is not a separator
public void notifyDataSetChanged ()
Since: API Level 1Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself.
public void notifyDataSetInvalidated ()
Since: API Level 1Notifies 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.
public void registerDataSetObserver (DataSetObserver observer)
Since: API Level 1Register an observer that is called when changes happen to the data used by this adapter.
Parameters
observer
|
the object that gets notified when the data set changes.
|
---|
public void unregisterDataSetObserver (DataSetObserver observer)
Since: API Level 1Unregister an observer that has previously been registered with this adapter via
registerDataSetObserver(DataSetObserver)
.Parameters
observer
|
the object to unregister.
|
---|
No comments:
Post a Comment