Use of the android spinner Control

Source: Internet
Author: User

1. UI file: spinner. xml

 
<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: Orientation = "vertical"> <textview Android: id = "@ + ID/textview1" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "textview"/> <spinner Android: id = "@ + ID/spinner1" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: drawselectid Top = "true" Android: prompt = "@ string/city_message"/> </linearlayout>

 

2. spinneraciti.pdf. Java File

Public class spinneractivity extends activity {private spinner; Private Static final string [] city = {"Spinner Item1", "Spinner item2", "Spinner item3", "Spinner item4 "}; @ override protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. spinner); spinner = (spinner) findviewbyid (R. id. spinner1); arrayadapter <string> adapter = new arrayada Pter <string> (this, android. r. layout. simple_spinner_item, city); spinner. setadapter (adapter); spinner. setonitemselectedlistener (New adapterview. onitemselectedlistener () {public void onitemselected (adapterview <?> Arg0, view arg1, int arg2, long arg3) {toast. maketext (spinneractivity. this, City [arg2], toast. length_short ). show ();} public void onnothingselected (adapterview <?> Arg0 ){}});}}

3 .. Use a simulator.

Related Article

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.