Professional Documents
Culture Documents
Spinners
Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one.
IN THIS DOCUMENT Populate the Spinner with User Choices Responding to User Selections
KEY CLASSES S p i n n e r S p i n n e r A d a p t e r A d a p t e r V i e w . O n I t e m S e l e c t e d L i s t e n e r
You can add a spinner to your layout with the S p i n n e r( / r e f e r e n c e / a n d r o i d / w i d g e t / S p i n n e r . h t m l )object. You should usually do so in your XML layout with a < S p i n n e r > element. For example: < S p i n n e r a n d r o i d : i d = " @ + i d / p l a n e t s _ s p i n n e r " a n d r o i d : l a y o u t _ w i d t h = " f i l l _ p a r e n t " a n d r o i d : l a y o u t _ h e i g h t = " w r a p _ c o n t e n t "/ > To populate the spinner with a list of choices, you then need to specify a S p i n n e r A d a p t e r ( / r e f e r e n c e / a n d r o i d / w i d g e t / S p i n n e r A d a p t e r . h t m l )in your A c t i v i t y ( / r e f e r e n c e / a n d r o i d / a p p / A c t i v i t y . h t m l )or F r a g m e n t( / r e f e r e n c e / a n d r o i d / a p p / F r a g m e n t . h t m l )source code.
developer.android.com/guide/topics/ui/controls/spinner.html
1/3
18/07/13
( / r e f e r e n c e / a n d r o i d / w i d g e t / A r r a y A d a p t e r . h t m l ) :
method allows you to create an A r r a y A d a p t e r( / r e f e r e n c e / a n d r o i d / w i d g e t / A r r a y A d a p t e r . h t m l )from the string array. The third argument for this method is a layout resource that defines how the selected choice appears in the spinner control. The s i m p l e _ s p i n n e r _ i t e m ( / r e f e r e n c e / a n d r o i d / R . l a y o u t . h t m l # s i m p l e _ s p i n n e r _ i t e m )layout is provided by the platform and is the default layout you should use unless you'd like to define your own layout for the spinner's appearance. You should then call s e t D r o p D o w n V i e w R e s o u r c e ( i n t )
( / r e f e r e n c e / a n d r o i d / w i d g e t / A r r a y A d a p t e r . h t m l # s e t D r o p D o w n V i e w R e s o u r c e ( i n t ) )to specify the layout the
adapter should use to display the list of spinner choices (s i m p l e _ s p i n n e r _ d r o p d o w n _ i t e m ( / r e f e r e n c e / a n d r o i d / R . l a y o u t . h t m l # s i m p l e _ s p i n n e r _ d r o p d o w n _ i t e m )is another standard layout defined by the platform). Call s e t A d a p t e r ( )( / r e f e r e n c e / a n d r o i d / w i d g e t / A d a p t e r V i e w . h t m l # s e t A d a p t e r ( T ) )to apply the adapter to your S p i n n e r( / r e f e r e n c e / a n d r o i d / w i d g e t / S p i n n e r . h t m l ) .
developer.android.com/guide/topics/ui/controls/spinner.html
2/3
18/07/13
t e m S e l e c t e d L i s t e n e r ) ) :
developer.android.com/guide/topics/ui/controls/spinner.html
3/3