在你的活动中添加微调器
在/res/values/strings.xml 中:
<string-array name="spinner_options">
<item>Option 1</item>
<item>Option 2</item>
<item>Option 3</item>
</string-array>
在布局 XML 中:
<Spinner
android:id="@+id/spinnerName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/spinner_options" />
在活动中:
Spinner spinnerName = (Spinner) findViewById(R.id.spinnerName);
spinnerName.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String chosenOption = (String) parent.getItemAtPosition(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {}
});