Android Self-study note the Spinner drop-down box features, use

Source: Internet
Author: User

Spinner:
is a control similar to a drop-down list from which the user chooses the appropriate option!
The data in the spinner needs to be populated with a adapter (adapter).

Use:


layout file Activity_main.xml:
<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><spinner        android:id= "@+id/spinner"        android:layout_width= "match_parent"        android:layout_ height= "Wrap_content"        ></Spinner>    <textview        android:id= "@+id/textview"        android: Layout_width= "Match_parent"        android:layout_height= "wrap_content"        /></span>




class file Mainactivity.java:


<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" >package Com.example.administrator.spinner1;import Android.support.v7.app.actionbaractivity;import Android.os.bundle;import Android.view.menu;import Android.view.menuitem;import Android.view.View;import Android.widget.adapterview;import Android.widget.arrayadapter;import Android.widget.spinner;import Android.widget.textview;import Java.util.arraylist;import Java.util.list;public class MainActivity extends    actionbaractivity {private Spinner Spinner;    Private TextView TextView;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Spinner = (spinner) Findviewbyid (R.id.spinner);        TextView = (TextView) Findviewbyid (R.id.textview);  Spinner.setprompt ("Please select three people:");        The drop-down box starts to prompt for the final list list = new ArrayList ();        Final List List1 = new ArrayList ();     Final List list2 = new ArrayList ();   List.add ("Zhao Yun");        List.add ("Zhuge Liang");        List.add ("Guan Yu");        List.add ("bu");        List1.add ("character Zilong");        List1.add ("The word Ming");        List1.add ("Word cloud length");        List1.add ("word first");        List2.add ("Armed forces: all-in-all intelligence: [+] Endurance: 80");        List2.add ("Force: ten \ n: 20");        List2.add ("Armed forces: the strength of the intellect: the Endurance: 80");        List2.add ("Armed Forces: the Intelligence: the Endurance: 70"); Arrayadapter adpter = new Arrayadapter (this, Android.        R.layout.simple_spinner_item,list);        Spinner.setadapter (Adpter); Spinner.setonitemselectedlistener (New Adapterview.onitemselectedlistener () {@Override public void O                Nitemselected (adapterview<?> Parent, view view, int position, long ID) {                Textview.settext ("Selected:" +list.get (position) + ": \ T" +list1.get (position));            Textview.append ("\ n personal information: \ n" +list2.get (position)); } @Override public void OnnothingselectEd (adapterview<?> parent) {}}); }}</span>



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Self-study note the Spinner drop-down box features, use

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.