diff options
| author | 2010-06-11 22:28:38 +0200 | |
|---|---|---|
| committer | 2010-06-12 10:51:06 +0200 | |
| commit | 8c582ef859fcbbb97623d22024c3ecb32b65c5ef (patch) | |
| tree | b831c1b38f35b29bfbf45f5741740bd670dc898f | |
| parent | fdedc522993ccbde6ba95b519ac81e32449959c8 (diff) | |
Added an addAll to the ArrayAdapter
It behaves the same as ArrayList.addAll, since
the Object containing the Objects in the Adapter
is a List. Now you can add multiple Objects
at once, instead of looping over a Collection
and add all items one by one.
Unittests will be submitted to the cts project
Change-Id: I16f3286a8ca4cda7eb9f1a99c2aab1cc45b2550f
| -rw-r--r-- | api/current.xml | 28 | ||||
| -rw-r--r-- | core/java/android/widget/ArrayAdapter.java | 43 |
2 files changed, 68 insertions, 3 deletions
diff --git a/api/current.xml b/api/current.xml index eb014513c1f9..e06996dcfb5b 100644 --- a/api/current.xml +++ b/api/current.xml @@ -181308,6 +181308,32 @@ <parameter name="object" type="T"> </parameter> </method> +<method name="addAll" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="collection" type="java.util.Collection<? extends T>"> +</parameter> +</method> +<method name="addAll" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="items" type="T..."> +</parameter> +</method> <method name="clear" return="void" abstract="false" @@ -197251,7 +197277,7 @@ deprecated="not deprecated" visibility="public" > -<parameter name="arg0" type="T"> +<parameter name="t" type="T"> </parameter> </method> </interface> diff --git a/core/java/android/widget/ArrayAdapter.java b/core/java/android/widget/ArrayAdapter.java index 32e55048ed18..03ada94d667e 100644 --- a/core/java/android/widget/ArrayAdapter.java +++ b/core/java/android/widget/ArrayAdapter.java @@ -24,6 +24,7 @@ import android.view.ViewGroup; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Comparator; import java.util.Collections; @@ -83,7 +84,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable { */ private boolean mNotifyOnChange = true; - private Context mContext; + private Context mContext; private ArrayList<T> mOriginalValues; private ArrayFilter mFilter; @@ -181,6 +182,44 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable { } /** + * Adds the specified Collection at the end of the array. + * + * @param collection The Collection to add at the end of the array. + */ + public void addAll(Collection<? extends T> collection) { + if (mOriginalValues != null) { + synchronized (mLock) { + mOriginalValues.addAll(collection); + if (mNotifyOnChange) notifyDataSetChanged(); + } + } else { + mObjects.addAll(collection); + if (mNotifyOnChange) notifyDataSetChanged(); + } + } + + /** + * Adds the specified items at the end of the array. + * + * @param items The items to add at the end of the array. + */ + public void addAll(T ... items) { + if (mOriginalValues != null) { + synchronized (mLock) { + for (T item : items) { + mOriginalValues.add(item); + } + if (mNotifyOnChange) notifyDataSetChanged(); + } + } else { + for (T item : items) { + mObjects.add(item); + } + if (mNotifyOnChange) notifyDataSetChanged(); + } + } + + /** * Inserts the specified object at the specified index in the array. * * @param object The object to insert into the array. @@ -236,7 +275,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable { */ public void sort(Comparator<? super T> comparator) { Collections.sort(mObjects, comparator); - if (mNotifyOnChange) notifyDataSetChanged(); + if (mNotifyOnChange) notifyDataSetChanged(); } /** |