diff options
| author | Alan Viverette <alanv@google.com> | 2014-06-17 23:48:49 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-06-17 22:59:52 +0000 |
| commit | e35a0b30ac0fa6592d834aa29b30296fb5bbf703 (patch) | |
| tree | 3edc3824d42ea390f8fc08f4364565c94bdf2849 /core/java | |
| parent | 93afb5f1d9b557fe1c1010b3a56d3f18235dd4ec (diff) | |
| parent | d52697784fcf91b62a1a487a0229c1a6548853cd (diff) | |
| download | frameworks_base-e35a0b30ac0fa6592d834aa29b30296fb5bbf703.zip frameworks_base-e35a0b30ac0fa6592d834aa29b30296fb5bbf703.tar.gz frameworks_base-e35a0b30ac0fa6592d834aa29b30296fb5bbf703.tar.bz2 | |
Merge "Throw exception when a bad adapter is passed to Spinner"
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/widget/Spinner.java | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/core/java/android/widget/Spinner.java b/core/java/android/widget/Spinner.java index 9601d4a..9914800 100644 --- a/core/java/android/widget/Spinner.java +++ b/core/java/android/widget/Spinner.java @@ -25,6 +25,7 @@ import android.content.res.TypedArray; import android.database.DataSetObserver; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.util.AttributeSet; @@ -427,9 +428,15 @@ public class Spinner extends AbsSpinner implements OnClickListener { * {@link Adapter#getItemViewType(int) getItemViewType(int)} on the object * returned from {@link #getAdapter()} will always return 0. Calling * {@link Adapter#getViewTypeCount() getViewTypeCount()} will always return - * 1. + * 1. On API {@link Build.VERSION_CODES#L} and above, attempting to set an + * adapter with more than one view type will throw an + * {@link IllegalArgumentException}. + * + * @param adapter the adapter to set * * @see AbsSpinner#setAdapter(SpinnerAdapter) + * @throws IllegalArgumentException if the adapter has more than one view + * type */ @Override public void setAdapter(SpinnerAdapter adapter) { @@ -437,6 +444,12 @@ public class Spinner extends AbsSpinner implements OnClickListener { mRecycler.clear(); + final int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; + if (targetSdkVersion >= Build.VERSION_CODES.L + && adapter != null && adapter.getViewTypeCount() != 1) { + throw new IllegalArgumentException("Spinner adapter view type count must be 1"); + } + if (mPopup != null) { mPopup.setAdapter(new DropDownAdapter(adapter)); } else { |
