Drop-down list box "Android 3"

Source: Internet
Author: User

Spinner (drop-down list box)

Method

Describe

Charsequence getprompt ()

Get hint text

void Setprompt (Charsequence prompt)

Set the ToolTip text for a component

void Setadapter ()

Set drop-down list box

Void Setonitemclicklistener

(Adapterview.onitemclicklistener L)

Set Options Click events

How drop-down lists are configured

A. resource file configuration

First step: Configure in String.xml

<?XML version= "1.0" encoding= "Utf-8"?><Resources>    <String-arrayname= "Pro">        <Item>"Hunan Province"</Item>        <Item>"Guangdong Province"</Item>        <Item>"Sichuan Province"</Item>        <Item>"Jiangsu Province"</Item>    </String-array></Resources>
String.xml

B. Adapter-specific resources

The first type: resource configuration

arrayadapter<charsequence> adapter =

Arrayadapter.createfromresource (this, resource ID, List-displayed style);

1  Public classSpinneradapterextendsActivity {2 @Override3      Public voidonCreate (Bundle savedinstancestate) {4         Super. OnCreate (savedinstancestate);5 Setcontentview (r.layout.main);6 7         //define an adapter to read the contents of a province in an XML file8arrayadapter<charsequence> adapter =Arrayadapter.createfromresource (9                  This, R.array.pro, Android. R.layout.simple_spinner_item);Ten         //set list display style Adapter.setdropdownviewresource (Android. R.layout.simple_spinner_dropdown_item); One  A         //Remove the drop-down box from the XML file -         FinalSpinner spin = (Spinner)Super. Findviewbyid (R.id.spinner01); -Spin.setadapter (adapter);//The adapter object for the province is passed in theSpin.setprompt ("Select Province"); -         } -}
Resource Configuration

Second type: List configuration

list< charsequence > List=new arraylist< charsequence > ();

List. Add ();

Arrayadapter <CharSequence> adapter =

Arrayadapter.createfromresource (this, list display style, collection data [list]);

//CollectionList<charsequence> list=NewArraylist<charsequence>(); List.add ("Hunan Province"); List.add ("Guangdong province"); List.add ("Sichuan Province");//define an adapter to read the contents of a province in an XML filearrayadapter<charsequence> adapter = Arrayadapter.createfromresource ( This, Android. r.layout.simple_spinner_item,list);//Set the list display styleAdapter.setdropdownviewresource (Android. R.layout.simple_spinner_dropdown_item);//first drop -down box    FinalSpinner spin = (Spinner)Super. Findviewbyid (R.id.spinner01);    Spin.setadapter (adapter); //The adapter object for the province is passed inSpin.setprompt ("Select Province"); list configuration
List Configuration

"Set list display style"

Adapter.setdropdownviewresource (Android. R.layout.simple_spinner_dropdown_item);

Drop-down list box "Android 3"

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.