Use of spinner in Android

Source: Internet
Author: User

This blog post describes how to use the basic spinner

First write the Code section in XML

<spinner android:id= "@+id/myspinner" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" />

Write the file section in Strings.xml again.

<string-array name= "Tongxue" > <item> hou </item> <item> Zhang </ite M> <item> Zhao </item> <item> Lee </item> <item> Lee </item> <ite M> Liu </item> </string-array>

Finally, let's show you the Code section of the activity.

public class mainactivity extends activity {private spinner spin;      @Override     protected void oncreate (bundle  savedinstancestate)  {        super.oncreate (savedInstanceState);         setcontentview (R.layout.activity_main);         spin= (Spinner) Findviewbyid (R.id.myspinner);         arrayadapter<charsequence> adapter=arrayadapter.createfromresource (this,  R.array.tongxue, android. R.layout.simple_spinner_item);         adapter.setdropdownviewresource ( Android. R.layout.simple_spinner_dropdown_item);         spin.setadapter (Adapter );         spin.setprompt ("Test");         spin.setonitemselectedlistener (New spinnerlis ());             }    //Define a listener     class SpinnerLis  implements onitemselectedlistener{@Overridepublic  void onitemselected (adapterview<?>  parent, view view,int position, long id)  {string selected= Parent.getitematposition (position). ToString (); Toast.maketext (Getapplicationcontext (),  selected, toast.length_long). Show (); @Overridepublic  void onnothingselected (adapterview<?> parent)  {}         }


This article is from the "Java White Battlefield" blog, be sure to keep this source http://8023java.blog.51cto.com/10117207/1664415

Use of spinner in Android

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.