The drop-down menu in Android, such as <select> in html, is the key to calling the setDropDownViewResource method to define the appearance of the drop-down menu in XML.
step:
1. Define Spinner control
Copy the codeThe code is as follows:
<Spinner
android:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/planet_prompt" /><!-- A String resource, so point to a string -->
2. Create a new Android XML file named arrays in the res/values/ folder
Copy the codeThe code is as follows:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Neptune</item>
</string-array>
</resources>
The contents in this file will be automatically added to the R file, and the reference is: This is a List of the user drop-down selections;
3. Add the following code to the onCreate method of Activity
Copy the codeThe code is as follows:
Spinner s = (Spinner) findViewById();
ArrayAdapter adapter2 = (this, , .simple_spinner_item);
(.simple_spinner_dropdown_item);
(adapter2);
OK!