Merge "Throw exception when a bad adapter is passed to Spinner"

This commit is contained in:
Alan Viverette
2014-06-17 23:48:49 +00:00
committed by Android (Google) Code Review

View File

@@ -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 {