Spin Control
In Android, the is the equivalent of the drop‑down selector you might find in other toolkits (e.g., in Java/Swing). Pressing the center button on the D‑pad pops up a selection dialog for the user to choose an item from. You basically get the ability to select from a list without taking up all the screen space of a , at the cost of an extra click or screen tap to make a change.
As with , you provide the adapter for data and child views via and hook in a listener object for selections via .
If you want to tailor the view used when displaying the drop‑down perspective, you need to configure the adapter, not the widget. Use the method to supply the resource ID of the view to use.
For example, culled from the sample project, here is an XML layout for a simple view with a :
This is the same view as shown in the previous section, just with a instead of a . The property controls whether the arrows are drawn on the selector button on the right side of the UI.
To populate and use the , we need some Java code:
Public class extends
Implements
Public onCreate
Super onCreate
SetContentView
FindViewById
FindViewById
SetOnItemSelectedListener this
New this
SetDropDownViewResource
SetAdapter
Public onItemSelected
SetText
Public onNothingSelected
Дата добавления: 2015-05-16; просмотров: 747;