How to Use Android Spinner

Source: Internet
Author: User

In today's mobile phone field, smartphones are the most popular. So how can we choose an excellent mobile phone system to meet our needs? Here, you can take a look at the Android system as a reference for your convenience. The content introduced today is about some basic concepts of Android Spinner.

● Set the Adapter and call the setAdapter () method.

● Append the Item selection time, call the setOnItemSelectedListener () method, and pass the AdapterView. OnItemSelectedListener instance as a parameter.

Android Spinner routine source code (Java)

 
 
  1. ArrayAdapter< String> adapter = new ArrayAdapter< String>(  
  2. this,  
  3. android.R.layout.simple_spinner_item);  
  4. adapter.setDropDownViewResource(  
  5. android.R.layout.simple_spinner_dropdown_item);  
  6. adapter.add("red");  
  7. adapter.add("green");  
  8. adapter.add("blue");  
  9. Spinner spinner = (Spinner) findViewById(id.spinner);  
  10. spinner.setAdapter(adapter);   
  11. spinner.setOnItemSelectedListener(new OnItemSelectedListener() {  
  12. @Override  
  13. public void onItemSelected(  
  14. AdapterView< ?> parent,  
  15. View view,  
  16. int position,  
  17. long id) {  
  18. Spinner spinner = (Spinner) parent;  
  19. Log.v("Test", "id = " + id + "("  
  20. + spinner.getSelectedItem().toString() + ")");  
  21. }  
  22. @Override  
  23. public void onNothingSelected(AdapterView< ?> parent) {  
  24. }  
  25. }); 

Resource)

 
 
  1. < Spinner android:id="@+id/spinner" 
  2. android:layout_height="wrap_content" 
  3. android:layout_width="fill_parent"/> 

The source code of Android Spinner is introduced here.

Related Article

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.