I have an error: setOnItemClickListener cannot be used with a spinner, what is wrong?

前端 未结 6 1656
感动是毒
感动是毒 2020-12-13 16:47

Kindly This is my code below, and I am pasting the error messages underneath: I am trying to use setOnItemClickListener on the spinner, is it permissible?

6条回答
  •  眼角桃花
    2020-12-13 17:12

    Kotlin:

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

    I wrote it because inline creating object from the interface is different.

提交回复
热议问题