onItemSelectedListener不适用于微调Kotlin

时间:2019-10-02 19:19:25

标签: android kotlin spinner

我正在使用kotlin,并且尝试使用从微调器中选择的itom做一些事情。我正在使用从另一个类似问题中获得的这段代码,但是根本无法正常工作。有人知道为什么吗?还是我想念的东西?

spinnerBooks.adapter = ArrayAdapter(this,android.R.layout.simple_spinner_item,spinnerBooksArray!!)
spinnerBooks.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
    override fun onNothingSelected(parent: AdapterView<*>?) {

    }

    override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
        val text = parent!!.getItemAtPosition(position).toString()
        Toast.makeText(this@AddAuction,"SELECTED: $text",Toast.LENGTH_SHORT).show()
    }

}

0 个答案:

没有答案