Spinner of Android controls

Source: Internet
Author: User

Spinner is used to display list items, similar to a set of single-box radiobutton. Here's a glimpse of its effect.

SOURCE download

I. Overview

Spinner is a control that selects only one item of all items at a time. Its entry comes from the adapter associated with it.

Second, important attributes

Android:prompt: Displays this prompt when the Spinner dialog box is closed

Iii. Important methods

    Setprompt (Charsequence Prompt): Sets the prompt to display when the spinner dialog box is closed

    PerformClick (): Call this view if it is defined Onclicklistener

    Setonitemclicklistener (Adapterview.onitemclicklistener L): Called when the item is clicked

    Ondetachedfromwindow (): Called when spinner is detached from the window.

Iv. Complete code

 Public classSpinnerdemoextendsActivity {@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);         Setcontentview (R.layout.spinnerpage); Spinner S1=(Spinner) Findviewbyid (R.id.spinnercolor); Arrayadapter<CharSequence> adapter =Arrayadapter.createfromresource ( This, R.array.colors, Android.         R.layout.simple_spinner_item); Adapter.setdropdownviewresource (Android.         R.layout.simple_spinner_dropdown_item);         S1.setadapter (adapter); S1.setonitemselectedlistener (NewOnitemselectedlistener () { Public voidonitemselected (Adapterview<?> Parent, view view,intPositionLongID) {Showtoast ("spinner1:position=" + position + "id=" +ID); }                      Public voidOnnothingselected (adapterview<?>parent) {Showtoast ("Spinner1:unselected");         }                 }); Spinner S2=(Spinner) Findviewbyid (r.id.spinnerplanet); Adapter= Arrayadapter.createfromresource ( This, R.array.planets, Android.         R.layout.simple_spinner_item); Adapter.setdropdownviewresource (Android.         R.layout.simple_spinner_dropdown_item);         S2.setadapter (adapter); S2.setonitemselectedlistener (NewOnitemselectedlistener () { Public voidonitemselected (Adapterview<?> Parent, view view,intPositionLongID) {Showtoast ("spinner2:position=" + position+1 + "id=" + id+1); }                      Public voidOnnothingselected (adapterview<?>parent) {Showtoast ("Spinner2:unselected");     }                 }); }    Private voidshowtoast (charsequence msg) {Toast.maketext ( This, MSG, Toast.length_short). Show (); }}

Transferred from: http://www.cnblogs.com/salam/archive/2010/10/07/1844980.html

Spinner of Android controls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.