Android APIs
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
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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

Summary

XML Attributes
Attribute Name Related Method Description
android:entries Reference to an array resource that will populate the Spinner. 
[Expand]
Inherited XML Attributes
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Constants
From class android.widget.AdapterView
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
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
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 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
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.

[Expand]
Inherited Methods
From class android.widget.AdapterView
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

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.

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

This corresponds to the global attribute resource symbol entries.

Related Methods

Public Constructors

public AbsSpinner (Context context)

Added in API level 1

Parameters
context

public AbsSpinner (Context context, AttributeSet attrs)

Added in API level 1

Parameters
context
attrs

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

Added in API level 1

Parameters
context
attrs
defStyleAttr

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

Added in API level 21

Parameters
context
attrs
defStyleAttr
defStyleRes

Public Methods

public CharSequence getAccessibilityClassName ()

Added in API level 23

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

public SpinnerAdapter getAdapter ()

Added in API level 1

Returns the adapter currently associated with this widget.

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

public int getCount ()

Added in API level 1

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.)

public View getSelectedView ()

Added in API level 1

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

public void onRestoreInstanceState (Parcelable state)

Added in API level 1

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.

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

public Parcelable onSaveInstanceState ()

Added in API level 1

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.

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

public int pointToPosition (int x, int y)

Added in API level 1

Maps a point to a position in the list.

Parameters
x X in local coordinate
y Y in local coordinate
Returns
int The position of the item which contains the specified point, or INVALID_POSITION if the point does not intersect an item.

public void requestLayout ()

Added in API level 1

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

See also:

public void setAdapter (SpinnerAdapter adapter)

Added in API level 1

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 The SpinnerAdapter to use for this Spinner

public void setSelection (int position, boolean animate)

Added in API level 1

Jump directly to a specific item in the adapter data.

Parameters
position
animate

public void setSelection (int position)

Added in API level 1

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

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

Protected Methods

protected ViewGroup.LayoutParams generateDefaultLayoutParams ()

Added in API level 1

Returns a set of default layout parameters. These parameters are requested when the View passed to addView(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

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Added in API level 1

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 horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.