如何在微调器中添加文本和值。以及如何在微调器中选择值。 (与html中的select选项相同。例如<select><option value="1">Volvo</option></select>
)
activity_main.xml中
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinner_title"/>
ActivityMain.java
Spinner spinner = (Spinner) findViewById(R.id.spinner);
List<String> categories = new ArrayList<String>();
categories.add("Spinner 1");
categories.add("Spinner 2");
categories.add("Spinner 3");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);