AbsSpinner


public abstract class AbsSpinner
extends AdapterView<SpinnerAdapter>

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.AdapterView<android.widget.SpinnerAdapter>
         ↳ android.widget.AbsSpinner


An abstract base class for spinner widgets. SDK users will probably not need to use this class.

Summary

XML attributes

android:entries Reference to an array resource that will populate the Spinner. 

Inherited XML attributes

Inherited constants

Inherited fields

Public constructors

AbsSpinner(Context context)
AbsSpinner(Context context, AttributeSet attrs)
AbsSpinner(Context context, AttributeSet attrs, int defStyleAttr)
AbsSpinner(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

void autofill(AutofillValue value)

Automatically fills the content of this view with the value.

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.

SpinnerAdapter getAdapter()

Returns the adapter currently associated with this widget.

int getAutofillType()

Describes the autofill type of this view, so an AutofillService can create the proper AutofillValue when autofilling the view.

AutofillValue getAutofillValue()

Gets the View's current autofill value.

int getCount()
View getSelectedView()
void onRestoreInstanceState(Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().

Parcelable onSaveInstanceState()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state.

int pointToPosition(int x, int y)

Maps a point to a position in the list.

void requestLayout()

Override to prevent spamming ourselves with layout requests as we place views

void setAdapter(SpinnerAdapter adapter)

The Adapter is used to provide the data which backs this Spinner.

void setSelection(int position, boolean animate)

Jump directly to a specific item in the adapter data.

void setSelection(int position)

Sets the currently selected item.

Protected methods

void dispatchRestoreInstanceState(SparseArray<Parcelable> container)

Override to prevent thawing of any views created by the adapter.

ViewGroup.LayoutParams generateDefaultLayoutParams()

Returns a set of default layout parameters.

void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

Inherited methods

XML attributes

android:entries

Reference to an array resource that will populate the Spinner. For static content, this is simpler than populating the Spinner programmatically.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

Public constructors

AbsSpinner

Added in API level 1
public AbsSpinner (Context context)

Parameters
context Context

AbsSpinner

Added in API level 1
public AbsSpinner (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

AbsSpinner

Added in API level 1
public AbsSpinner (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

AbsSpinner

Added in API level 21
public AbsSpinner (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Public methods

autofill

Added in API level 26
public void autofill (AutofillValue value)

Automatically fills the content of this view with the value.

Views support the Autofill Framework mainly by:

  • Providing the metadata defining what the view means and how it can be autofilled.
  • Implementing the methods that autofill the view.

onProvideAutofillStructure(android.view.ViewStructure, int) is responsible for the former, this method is responsible for latter.

This method does nothing by default, but when overridden it typically:

  1. Checks if the provided value matches the expected type (which is defined by getAutofillType()).
  2. Checks if the view is editable - if it isn't, it should return right away.
  3. Call the proper getter method on AutofillValue to fetch the actual value.
  4. Pass the actual value to the equivalent setter in the view.

For example, a text-field view could implement the method this way:

 @Override
 public void autofill(AutofillValue value) {
   if (!value.isText() || !this.isEditable()) {
      return;
   }
   CharSequence text = value.getTextValue();
   if (text != null) {
     this.setText(text);
   }
 }
 

If the value is updated asynchronously, the next call to AutofillManager#notifyValueChanged(View) must happen after the value was changed to the autofilled value. If not, the view will not be considered autofilled.

Note: After this method is called, the value returned by getAutofillValue() must be equal to the value passed to it, otherwise the view will not be highlighted as autofilled.

Parameters
value AutofillValue: value to be autofilled.

getAccessibilityClassName

Added in API level 23
public CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

getAdapter

Added in API level 1
public SpinnerAdapter getAdapter ()

Returns the adapter currently associated with this widget.

Returns
SpinnerAdapter The adapter used to provide this view's content.

getAutofillType

Added in API level 26
public int getAutofillType ()

Describes the autofill type of this view, so an AutofillService can create the proper AutofillValue when autofilling the view.

By default returns AUTOFILL_TYPE_NONE, but views should override it to properly support the Autofill Framework.

Returns
int Value is View.AUTOFILL_TYPE_NONE, View.AUTOFILL_TYPE_TEXT, View.AUTOFILL_TYPE_TOGGLE, View.AUTOFILL_TYPE_LIST, or View.AUTOFILL_TYPE_DATE

getAutofillValue

Added in API level 26
public AutofillValue getAutofillValue ()

Gets the View's current autofill value.

By default returns null, but subclasses should override it and return an appropriate value to properly support the Autofill Framework.

Returns
AutofillValue

getCount

Added in API level 1
public int getCount ()

Returns
int The number of items owned by the Adapter associated with this AdapterView. (This is the number of data items, which may be larger than the number of visible views.)

getSelectedView

Added in API level 1
public View getSelectedView ()

Returns
View The view corresponding to the currently selected item, or null if nothing is selected

onRestoreInstanceState

Added in API level 1
public void onRestoreInstanceState (Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state.
If you override this method you must call through to the superclass implementation.

Parameters
state Parcelable: The frozen state that had previously been returned by onSaveInstanceState().

onSaveInstanceState

Added in API level 1
public Parcelable onSaveInstanceState ()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.

Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.
If you override this method you must call through to the superclass implementation.

Returns
Parcelable Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save.

pointToPosition

Added in API level 1
public int pointToPosition (int x, 
                int y)

Maps a point to a position in the list.

Parameters
x int: X in local coordinate

y int: Y in local coordinate

Returns
int The position of the item which contains the specified point, or AdapterView.INVALID_POSITION if the point does not intersect an item.

requestLayout

Added in API level 1
public void requestLayout ()

Override to prevent spamming ourselves with layout requests as we place views

setAdapter

Added in API level 1
public void setAdapter (SpinnerAdapter adapter)

The Adapter is used to provide the data which backs this Spinner. It also provides methods to transform spinner items based on their position relative to the selected item.

Parameters
adapter SpinnerAdapter: The SpinnerAdapter to use for this Spinner

setSelection

Added in API level 1
public void setSelection (int position, 
                boolean animate)

Jump directly to a specific item in the adapter data.

Parameters
position int

animate boolean

setSelection

Added in API level 1
public void setSelection (int position)

Sets the currently selected item. To support accessibility subclasses that override this method must invoke the overridden super method first.

Parameters
position int: Index (starting at 0) of the data item to be selected.

Protected methods

dispatchRestoreInstanceState

Added in API level 1
protected void dispatchRestoreInstanceState (SparseArray<Parcelable> container)

Override to prevent thawing of any views created by the adapter.

Parameters
container SparseArray: The SparseArray which holds previously saved state.

generateDefaultLayoutParams

Added in API level 1
protected ViewGroup.LayoutParams generateDefaultLayoutParams ()

Returns a set of default layout parameters. These parameters are requested when the View passed to addView(android.view.View) has no layout parameters already set. If null is returned, an exception is thrown from addView.

Returns
ViewGroup.LayoutParams a set of default layout parameters or null

onMeasure

Added in API level 1
protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec int: horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

heightMeasureSpec int: vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.