Most visited

Recently visited

Added in API level 1

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


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

From class android.view.ViewGroup
From class android.view.View

Inherited constants

From class android.widget.AdapterView
From class android.view.ViewGroup
From class android.view.View

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

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

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.

Public constructors

AbsSpinner

Added in API level 1
AbsSpinner (Context context)

Parameters
context Context

AbsSpinner

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

Parameters
context Context
attrs AttributeSet

AbsSpinner

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

Parameters
context Context
attrs AttributeSet
defStyleAttr int

AbsSpinner

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

Parameters
context Context
attrs AttributeSet
defStyleAttr int
defStyleRes int

Public methods

getAccessibilityClassName

Added in API level 23
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
SpinnerAdapter getAdapter ()

Returns the adapter currently associated with this widget.

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

getCount

Added in API level 1
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
View getSelectedView ()

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

onRestoreInstanceState

Added in API level 1
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.

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

onSaveInstanceState

Added in API level 1
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.

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.

pointToPosition

Added in API level 1
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 INVALID_POSITION if the point does not intersect an item.

requestLayout

Added in API level 1
void requestLayout ()

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

See also:

setAdapter

Added in API level 1
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
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
void setSelection (int position)

Sets the currently selected item. To support accessibility subclasses that override this method must invoke the overriden 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
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
ViewGroup.LayoutParams generateDefaultLayoutParams ()

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

onMeasure

Added in API level 1
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.

See also:

Hooray!