Usage of spinner _2 (add adapter)

Source: Internet
Author: User

1. The main function of adding adapters is to be able to add spinner data flexibly

1  Packagecom.jtl.spinner_2;2 3 Importjava.util.ArrayList;4 Importjava.util.List;5 6 ImportAndroid.os.Bundle;7 Importandroid.app.Activity;8 ImportAndroid.view.Menu;9 ImportAndroid.widget.ArrayAdapter;Ten ImportAndroid.widget.Spinner; One ImportAndroid.widget.SpinnerAdapter; A  -  Public classMainactivityextendsActivity { -  the     //define a Spinner object -     //defines a list object that is used to store the contents of the drop-down menu options - Spinner SP1; - list List; + @Override -     protected voidonCreate (Bundle savedinstancestate) { +         Super. OnCreate (savedinstancestate); A Setcontentview (r.layout.activity_main); at          -         //list instantiated with Araaylist -         //Drop- down menu Add content -list=NewArrayList (); -List.add ("Android Phase 1")); -List.add ("Android Phase 2")); inList.add ("Android Phase 3")); -List.add ("Android Phase 4")); toList.add ("Android phase 5")); +List.add ("Android phase 6")); -List.add ("Android phase 7")); the          *          $sp1=(Spinner) Findviewbyid (r.id.sp_1);Panax Notoginseng         //Create a Spinneradapter adapter, -Spinneradapter adapter=NewArrayadapter (mainactivity. This,//Context Content theAndroid. R.layout.simple_list_item_1,//Add a drop- down menu layout file +             /*Textviewresourceid,*/                             //Add a drop- down menu layout file Alist);//Drop- down menu data source the         //add an adapter to the spinner object + Sp1.setadapter (adapter); -     } $ } $ //XML Layout File - /* - <linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" the xmlns:tools= "Http://schemas.android.com/tools" - android:layout_width= "Match_parent"Wuyi android:layout_height= "Match_parent" the android:gravity= "center" - android:orientation= "Horizontal" > Wu      - <textview android:layout_width= "100DP" About android:layout_height= "Wrap_content" $ android:text= "class:" - android:gravity= "center"/> -  - <spinner A android:id= "@+id/sp_1" + android:layout_width= "100DP" the android:layout_height= "Wrap_content" - android:gravity= "center" $ /> the  the </LinearLayout> the  the  - */

Usage of spinner _2 (add adapter)

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.