微调器的XML代码:
<Spinner
android:id="@+id/mySpinner"
https://stackoverflow.com/questions
style="@style/Widget.AppCompat.DropDownItem.Spinner"
android:layout_width="match_parent"
android:layout_height="70dp" />`
Run Code Online (Sandbox Code Playgroud)
.kotlin:
val myStrings = arrayOf("One", "Two" , "Three", "Four")
mySpinner.adapter = ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, myStrings)
mySpinner.onItemSelectedListener = object :
AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {
TODO("not implemented")
//To change body of created functions use File | Settings | File Templates.
}
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
TODO("not implemented")
//To change body of created functions use File | Settings | File Templates.
}
}}
Run Code Online (Sandbox Code Playgroud)
等于Edittext中的“提示”选项,我需要Spinner中的默认文本。