I am using AppCompatSpinner to show the list of states. Initially, I saved the first position item. Then After if I click the spinner and try to scroll slowly that time it goes to the previous position. if I scroll little fast it's working. During slow scroll and long press on the spinner, list item creates a problem.Can anybody know how to resolve this issue? here is my spinner.
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/stateSpinner"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/SpinnerStyle"/>
val adapter = ArrayAdapter(
context,
R.layout.spinner_item, stateList
)
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item)
stateSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(adapterView: AdapterView<*>, view: View, i: Int, l: Long) {
viewModelOffice.officeSelectedState.set(stateList.get(i))
}
override fun onNothingSelected(adapterView: AdapterView<*>) {
}
}
stateSpinner.adapter = adapter
stateSpinner.setSelection(selectedPosition)
}
In theme, I am just setting the colors.minimum version of the app is 21. Any Help will be Appreciated.
Finally it is worked for me
Problem is anroidx update libs
Resolve by revert version appcompat from "alpha02/alpha03" back to "alpha01"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
or better
implementation 'androidx.appcompat:appcompat:1.0.2' -> for more stable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With