Is there a way to use setOnClickListener with an Android Spinner?

后端 未结 2 1720
孤城傲影
孤城傲影 2020-12-16 23:58

The java.lang.RuntimeException is \"Don\'t call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead,\" but that is not correct. I am usin

2条回答
  •  再見小時候
    2020-12-17 00:41

    You will have to set the Click listener on the underlying view (normally a TextView with id: android.R.id.text1) of the spinner. To do so:

    • Create a custom Spinner
    • In the constructor (with attributes) create the spinner by supplying the layout android.R.layout.simple_spinner_item
    • Do a findViewById(android.R.id.text1) to get the TextView
    • Now set the onClickListener to the TextView

提交回复
热议问题