First knowledge of Spinner

Source: Internet
Author: User

Spinner is a drop-down list box, like a ListView, is also an indirect subclass of adapterview, a window that displays data.

< Spinner             Android:id = "@+id/spinner1"             android:layout_width= "Match_parent"            android:layout_height= "Wrap_ Content "            android:entries=" @array/spinner_name "            android:prompt = "@string/hello_world" />

Set the data source for spinner

<?XML version= "1.0" encoding= "Utf-8"?><Resources>    <String-arrayname= "Spinner_name">        <Item>Mercury</Item>        <Item>Venus</Item>        <Item>Earth</Item>        <Item>Mars</Item>        <Item>Jupiter</Item>        <Item>Saturn</Item>        <Item>Uranus</Item>        <Item>Neptune</Item>    </String-array></Resources>

Set adapter for spinner and add event responses

1      Public void Showspinner () {  2         Spinner Spinner = (Spinner) Findviewbyid (r.id.spinner2); 3         The Simple_spinner_item layout is provided by the platform and are the default layout you should use unless yo U ' d like-to-Define your own layout for the spinner ' s appearance.         Spinneradapter Spinneradapter = Arrayadapter. Createfromresource (Formactivity.this, R.array.spinner_name,Android.) R.layout.simple_spinner_item); 8         

Specify the layout to use when the list of choices appears | sets the layout resource to create the drop of views.
Spinneradapter. Setdropdownviewresource (Android. R.layout.simple_spinner_dropdown_item);

 9 spinner. Setadapter (spinneradapter);TenSpinner.Setonitemselectedlistener(NewOnitemselectedlistener () { +  - @Override +              Public voidOnitemselected (adapterview<?>Parent, view view, A                     intPositionLongID) { at                 //TODO auto-generated Method Stub -  - log.i (TAG, -"Showspinner:onitemselected" -+ ((TextView) view). GetText () + ":p osition" -+ID); in             } -  to @Override +              Public voidOnnothingselected (adapterview<?>parent) { -                 //TODO auto-generated Method Stub theLOG.I (TAG, "showspinner:onnothingselected"); *             } $         });Panax Notoginseng  -}

First knowledge of Spinner

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.