Use 1 for the Spinner, and use

Source: Internet
Author: User

Use 1 for the Spinner, and use
Use

I. Usage

1. Create a Spinner control in layout.

<Spinner
Android: id = "@ + id/spinner1"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
/>

2. Add data sources and display formats to the data adapter

String [] city = new String [] {"Beijing", "Shanghai", "Hong Kong", "Macao "};
ArrayAdapter <String> adapter = new ArrayAdapter <String> (this, android. R. layout. simple_spinner_dropdown_item, city );

3. Add a data adapter to the Spinner Control

Spinner1.setAdapter (adapter );

 

Ii. And code

Fry. Activity01

Package fry; import com. example. spinnerDemo. r; import android. app. activity; import android. OS. bundle; import android. widget. arrayAdapter; import android. widget. spinner; public class Activity01 extends Activity {private Spinner spinner1; @ Override protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stub super. onCreate (savedInstanceState); setContentView (R. layout. activity01); spinner1 = (Spinner) findViewById (R. id. spinner1); initSpinner1 ();} public void initSpinner1 () {String [] city = new String [] {"Beijing", "Shanghai", "Hong Kong ", "Macao"}; ArrayAdapter <String> adapter = new ArrayAdapter <String> (this, android. r. layout. simple_spinner_dropdown_item, city); spinner1.setAdapter (adapter );}}

/SpinnerDemo/res/layout/activity01.xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     android:orientation="vertical" > 6  7     <Spinner  8         android:id="@+id/spinner1" 9         android:layout_width="match_parent"10         android:layout_height="wrap_content"11         />12 13 </LinearLayout>

 

 

Iii. Notes

1. android. R. layout. simple_spinner_dropdown_item

2. String [] city = new String [] {"Beijing", "Shanghai", "Hong Kong", "Macao"}; String used

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.