Detailed explanation of Spinner drop-down list of Android UI components
Spinner drop-down list
The diagram corresponding to this layout:
Common attributes: Android: entries (specifies the string resource to be displayed by the spinner. It must be the string resource defined in the strings resource file) Android: spinnermode (the mode of the spinner, and the enumeration value has two values: dialog pop-up display and dropdown drop-down display) Android: dropdownwidth (the width of the drop-down box, usually DP) Android: prompt (when the value of spinnermode is dialog, the following list will pop up in a dialog box. If the value of spinnermode is dropdown, it has no effect. Note: the value here cannot directly use the direct string, but must use the reference (string resource))
1. Set the data item through entries and add the data value in strings under the values folder
In strings Add a set of array data items to XML, and then set the corresponding values by setting in entries
2. Set Android: spinnermode:
The value of dialog is displayed as a pop-up box
If the value is dropdown, the display is as follows:
Android: dropdownwidth sets the drop-down width
The effect is as follows:
Acquisition method of data source: set data through arrayadapter adapter >
What is an adapter: extract the same part of the control in the process of loading data into code, and call this part of code every time to generate the content to be returned, similar to the mold. A brief introduction to arrayadapter: arrayadapter adapter = new arrayadapter (this, Android. R.layout. Simple_spinner_dropdown_item, data);
Description of arrayadapter construction method:
1. Arrayadapter (context, resource, objects) parameter 1: context object parameter 2: ID of layout file. Note that the layout file has and can only have one textview label parameter 3: original data, list, collection or array. 2. Arrayadapter (context, textviewresourceid, objects) parameter 1: context object parameter 2: the ID of the layout file. Note that there is at least one textview label in the layout file. Parameter 3: parameter 2: the ID of the textview to display data in the layout file. Parameter 4: original data, list collection or array.
Listening events
The listening event used for spinner is setonitemselectedlistener (onitemselectedlistener listener)
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.