public class

Spinner

extends Spinner
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.AdapterView<T extends android.widget.Adapter>
         ↳ android.widget.AbsSpinner
           ↳ android.widget.Spinner
             ↳ sofia.widget.Spinner<E>

Class Overview

A subclass of android.widget.Spinner that is easier to use. It provides methods like those in the List interface (add, remove, get, and set, among others) to manipulate the contents of the list, as well as an accessor method getList() that returns a List that automatically refreshes the spinner when its structure is changed.

Summary

[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
Spinner(Context context)
Creates a new Spinner.
Spinner(Context context, AttributeSet attrs)
Creates a new Spinner.
Spinner(Context context, AttributeSet attrs, int defStyle)
Creates a new Spinner.
Public Methods
void add(int index, E item)
Inserts an item into the spinner at the specified index.
boolean add(E item)
Adds an item to the spinner.
boolean addAll(int index, Collection<? extends E> collection)
Inserts the items in the specified collection into the spinner at the specified index.
boolean addAll(Collection<? extends E> collection)
Adds the items in the specified collection to the spinner.
void clear()
Removes all items from the spinner.
E get(int index)
Gets the element at the specified index from the spinner.
List<E> getList()
Gets the list of items that is managed by this spinner.
E getSelectedItem()
Gets the currently selected item in the spinner.
void refresh()
Refreshes the spinner to update its contents from the list it manages.
E remove(int index)
Removes the item at the specified index from the spinner.
boolean remove(E item)
Removes the specified item from the spinner.
E set(int index, E item)
Replaces the element at the specified index from the spinner with another item.
[Expand]
Inherited Methods
From class android.widget.Spinner
From class android.widget.AbsSpinner
From class android.widget.AdapterView
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.content.DialogInterface.OnClickListener
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

Public Constructors

public Spinner (Context context)

Creates a new Spinner.

Parameters
context the context

public Spinner (Context context, AttributeSet attrs)

Creates a new Spinner.

Parameters
context the context
attrs the attribute set from the layout XML file

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

Creates a new Spinner.

Parameters
context the context
attrs the attribute set from the layout XML file
defStyle the default style ID

Public Methods

public void add (int index, E item)

Inserts an item into the spinner at the specified index.

Parameters
index the index where the new item should be inserted
item the item to add to the spinner
Returns
  • true if the item could be added, or false if it could not

public boolean add (E item)

Adds an item to the spinner.

Parameters
item the item to add to the spinner
Returns
  • true if the item could be added, or false if it could not

public boolean addAll (int index, Collection<? extends E> collection)

Inserts the items in the specified collection into the spinner at the specified index.

Parameters
index the index where the new items should be inserted
collection the items to add to the spinner
Returns
  • true if the items could be added, or false if they could not

public boolean addAll (Collection<? extends E> collection)

Adds the items in the specified collection to the spinner.

Parameters
collection the items to add to the spinner
Returns
  • rue if the items could be added, or false if they could not

public void clear ()

Removes all items from the spinner.

public E get (int index)

Gets the element at the specified index from the spinner.

Parameters
index the index of the item to retrieve
Returns
  • the item at the specified index

public List<E> getList ()

Gets the list of items that is managed by this spinner. Changes made to the structure of the list returned by this method (that is, adding, removing, or replacing items) will be immediately reflected in the spinner. You only need to explicitly refresh() the list if you make a change to an element inside the list without directly modifying the list itself.

Returns
  • the List of items managed by this spinner

public E getSelectedItem ()

Gets the currently selected item in the spinner.

Returns
  • the currently selected item in the spinner, or null if there is no item selected

public void refresh ()

Refreshes the spinner to update its contents from the list it manages. This method does not need to be called after methods like add or remove -- it only needs to be called if you change a property of one of the elements in the list (for example, by calling a setter) without modifying the structure of the list itself.

public E remove (int index)

Removes the item at the specified index from the spinner.

Parameters
index the index of the item to be removed
Returns
  • the item that was removed

public boolean remove (E item)

Removes the specified item from the spinner.

Parameters
item the item to remove from the spinner
Returns
  • true if the item was found and removed, or false if it was not

public E set (int index, E item)

Replaces the element at the specified index from the spinner with another item.

Parameters
index the index of the item to retrieve
item the item to put into the spinner
Returns
  • the item previously at the specified index