Data Binding Implementation of the Spinner control in Android Studio

Source: Internet
Author: User

Data Binding Implementation of the Spinner control in Android Studio

This section describes how to set a data source for the Spinner control in a set. The procedure is as follows:

1. On the Android Studio interface, select "Project" and expand "app"-> "res"-> "layout" to open activity_main.xml and add a Spinner control. The Code is as follows:

 

 


 

 

2. Find the MainActivity. java file under "app"> "java" and define several variables. The Code is as follows:

 

 private List
 
   eduList = null; private ArrayAdapter
  
    eduAdapter = null; private Spinner eduSpinner= null;
  
 

 


3. Add the following method after the OnCreate method of Activity:

 

// Find the Spinner control eduSpinner = (Spinner) super. findViewById (R. id. eduSpinner); eduSpinner. setPrompt ("select your degree:"); eduList = new ArrayList
 
  
(); EduList. add (""); eduList. add ("Undergraduate"); eduList. add ("master"); eduList. add ("other"); eduAdapter = new ArrayAdapter
  
   
(This, android. R. layout. simple_spinner_item, eduList); eduAdapter. setDropDownViewResource (android. R. layout. simple_spinner_dropdown_item); eduSpinner. setAdapter (eduAdapter );
  
 

 

 

4. Run the program. The corresponding data has been bound to the Spinner, as shown in:


 

The bound data can be obtained from the server through WebService, and then bound to the Spinner control.

 

 

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.