1,xml:
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/buttonGetData"
app:layout_constraintEnd_toStartOf="@+id/buttonGetData"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/buttonGetData" />
2,java代码:
点击弹出提示
private void changeSpinner() {
spinnerArr.add("yangliwei");
spinnerArr.add("heheda");
arrayAdapter = new ArrayAdapter(getContext(), android.R.layout.simple_dropdown_item_1line, spinnerArr);
spinner.setAdapter(arrayAdapter);
spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
showToast.showTextToast(getContext(),String.valueOf(spinnerArr.get(position)));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}