public abstract class

AbsSpinner

extends AdapterView<T extends Adapter>
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.AdapterView<T extends android.widget.Adapter>
         ↳ android.widget.AbsSpinner
Known Direct 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
Public Constructors
AbsSpinner(Context context)
AbsSpinner(Context context, AttributeSet attrs)
AbsSpinner(Context context, AttributeSet attrs, int defStyle)
Public Methods
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.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

XML Attributes

android:entries

Since: API Level

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)

Since: API Level 1

public AbsSpinner (Context context, AttributeSet attrs)

Since: API Level 1

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

Since: API Level 1

Public Methods

public SpinnerAdapter getAdapter ()

Since: API Level 1

Returns the adapter currently associated with this widget.

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

public int getCount ()

Since: API Level 1

Returns
  • 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 view.)

public View getSelectedView ()

Since: API Level 1

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

public void onRestoreInstanceState (Parcelable state)

Since: 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 ()

Since: 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
  • 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)

Since: API Level 1

Maps a point to a position in the list.

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

public void requestLayout ()

Since: API Level 1

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

See Also

public void setAdapter (SpinnerAdapter adapter)

Since: 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)

Since: API Level 1

Jump directly to a specific item in the adapter data.

public void setSelection (int position)

Since: 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 ()

Since: 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
  • a set of default layout parameters or null

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Since: 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 overriden 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.