Android Kotlin onItemSelectedListener for spinner not working

后端 未结 6 1132
盖世英雄少女心
盖世英雄少女心 2021-02-03 18:12

I have a spinner with some items (strings). I want to add the selected items to a list. I read online that I should use the onItemSelectedListenerrather than the

6条回答
  •  误落风尘
    2021-02-03 18:37

    (in Kotlin)Use this code:

    yourSpinner?.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
            override fun onNothingSelected(parent: AdapterView<*>?) {
    
            }
    
            override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
    
            }
    
        }
    

提交回复
热议问题