Android Spinner:当我在代码中设置ArrayAdapter时,Android调用onItemSelected。只有当用户单击微调项时才可能调用?
收听者
binding.spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(adapterView: AdapterView<*>?, view: View, i: Int, l: Long) {
value = binding.spinner.selectedItem.toString()
when (value) {
'a' -> {
valueId = 1
Log.d("onItemSelected", "valueId = 1")
}
'b' -> {
valueId = 2
Log.d("onItemSelected", "valueId = 2")
}
else -> {
valueId = 0
Log.d("onItemSelected", "valueId = 0")
}
}
}
override fun onNothingSelected(adapterView: AdapterView<*>?) { return }
}
字符串
旋转调整器
val values = arrayOf('Choice : ', 'a', 'b', 'c')
val adapterSpinner = ArrayAdapter(mContext, android.R.layout.simple_spinner_dropdown_item, values)
binding.spinner.adapter = adapterSpinner
型
是否可以用其他解决方案更改微调器上的值?
1条答案
按热度按时间ymdaylpp1#
我找到了解决方案。这是可能的Android Spinner与ListPopupWindow的替代品。我可以改变适配器,而无需调用事件onItemSelected