androidkotlinandroid-spinner

Android : Spinner : set ArrayAdapter in code want no call onItemSelected and only call when user click on spinner


Android Spinner : When i set ArrayAdapter in code, android call onItemSelected. it's possible only call when user click on spinner items ?

listener

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 }
    }

spinner setting adapteur

val values = arrayOf('Choice : ', 'a', 'b', 'c')  
val adapterSpinner = ArrayAdapter(mContext, android.R.layout.simple_spinner_dropdown_item, values)
            binding.spinner.adapter = adapterSpinner

May be it s possible to change values on spinner with other solution ?


Solution

  • I find the solution. It s possible with alternative of Android Spinner with ListPopupWindow. I can change adapter without call event onItemSelected.