Functions and usage of the slip-down box of the Android self-study notes

Source: Internet
Author: User

Functions and usage of the slip-down box of the Android self-study notes
Spinner:
Is a type of control similar to the drop-down list. You can select the corresponding option!
The data in the Spinner needs to be filled with an Adapter.

Usage:

 

Layout file activity_main.xml:
     
 




Class file MainActivity. java:

 

 

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 (select a Three Kingdoms character :); // The following prompt is displayed in the drop-down box: 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 (LV bu); list1.add (zi Zi Long); list1.add (zi Kong Ming); list1.add (zi yun long); list1.add (zi Feng Xian); list2.add (Force: 90 intelligence: 70 endurance: 80); list2.add (force: 10 intelligence: 100 endurance: 20); list2.add (Force: 95 intelligence: 60 endurance: 80); list2.add (Force: 100 intelligence: 50 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 onItemSelected (AdapterView
 Parent, View view, int position, long id) {textView. setText (selected: + list. get (position) +: + list1.get (position); textView. append (personal information: + list2.get (position) ;}@ Override public void onNothingSelected (AdapterView
 Parent ){}});}}


 


 

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.