Am android developer and i always had a problem with spinner and its listener
this is my code
stateSpinner?.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {
toast(“Please select state”)
}
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
// val state = stateSpinner.selectedItem as States
val state = parent?.getItemAtPosition(position) as States
// toast("state id :${state.id} , state name :${state.arName}")
Log.d("ccccc" , state.toString())
stateId = state.id
loadCities(stateId)
}
}
i write it and tested its works and after couple of days the listener not triggered or called and when i select any item of spinner nothing happens either logcat or toast or anything .
StackOverflow might be a better place to ask this kind of questions.
Anyway. From where are you calling “stateSpinner?..” ? From a fragment? Do you use kotlin synthetic and calling it from onCreateView instead of onViewCreated and stateSpinner is actually null? Log if stateSpinner is null. Just a wild guess.
first i put it in fragment and called in onViewCreated and as i said its stopped without i touch this fragment , and i thought that the problem from the fragment , and changed to activity and also nothing work here , someone in a telegram group hinted me that maybe the problem from the scroll view if i put it in a scroll view , i delete scroll view and nothing change
How do I bind Map<String, String> to AppCompatSpinner via data binding .
And also onItemSelected does not seem to exist for AppCompatSpinner from AndroidX.
I know it to set from ArrayAdapter , but i want to move UI logic code to xml than activity or fragments