public abstract class ArrayAdapterCompat2<T>
extends android.widget.BaseAdapter
implements android.widget.Filterable
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 Adapter.getView(int, View, ViewGroup)
and inflate a view resource.
For a code example, see
the
CustomChoiceList sample.
For an example of using an array adapter with a ListView, see the Adapter Views guide.
For an example of using an array adapter with a Spinner, see the Spinners guide.
Note:
If you are considering using array adapter with a ListView, consider using
androidx.recyclerview.widget.RecyclerView instead.
RecyclerView offers similar features with better performance and more flexibility than
ListView provides.
See the
Recycler View guide.
| 构造器和说明 |
|---|
ArrayAdapterCompat2(android.content.Context context) |
ArrayAdapterCompat2(android.content.Context context,
T[] objects)
Constructor
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
add(T object)
Adds the specified object at the end of the array.
|
void |
addAll(java.util.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.
|
android.content.Context |
getContext()
Returns the context associated with this array adapter.
|
int |
getCount() |
android.widget.Filter |
getFilter() |
T |
getItem(int position) |
long |
getItemId(int position) |
int |
getPosition(T item)
Returns the position of the specified item in the array.
|
void |
insert(T object,
int index)
Inserts the specified object at the specified index in the array.
|
void |
notifyDataSetChanged() |
void |
remove(T object)
Removes the specified object from the array.
|
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(java.util.Comparator<? super T> comparator)
Sorts the content of this adapter using the specified comparator.
|
areAllItemsEnabled, getAutofillOptions, getDropDownView, getItemViewType, getViewTypeCount, hasStableIds, isEmpty, isEnabled, notifyDataSetInvalidated, registerDataSetObserver, setAutofillOptions, unregisterDataSetObserverpublic ArrayAdapterCompat2(android.content.Context context)
public ArrayAdapterCompat2(android.content.Context context,
T[] objects)
context - The current context.objects - The objects to represent in the ListView.public void add(T object)
object - The object to add at the end of the array.public void addAll(java.util.Collection<? extends T> collection)
collection - The Collection to add at the end of the array.java.lang.UnsupportedOperationException - if the addAll operation
is not supported by this listjava.lang.ClassCastException - if the class of an element of the specified
collection prevents it from being added to this listjava.lang.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 nulljava.lang.IllegalArgumentException - if some property of an element of the
specified collection prevents it from being added to this listpublic void addAll(T... items)
items - The items to add at the end of the array.public void insert(T object, int index)
object - The object to insert into the array.index - The index at which the object must be inserted.public void remove(T object)
object - The object to remove.public void clear()
public void sort(java.util.Comparator<? super T> comparator)
comparator - The comparator used to sort the objects contained
in this adapter.public void notifyDataSetChanged()
notifyDataSetChanged 在类中 android.widget.BaseAdapterpublic void setNotifyOnChange(boolean notifyOnChange)
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.notifyOnChange - if true, modifications to the list will
automatically call notifyDataSetChanged()public android.content.Context getContext()
public int getCount()
getCount 在接口中 android.widget.Adapterpublic T getItem(int position)
getItem 在接口中 android.widget.Adapterpublic int getPosition(T item)
item - The item to retrieve the position of.public long getItemId(int position)
getItemId 在接口中 android.widget.Adapterpublic android.widget.Filter getFilter()
getFilter 在接口中 android.widget.Filterable