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.