Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

setSelectedIndex crash #166

Open
npabion opened this issue Jun 20, 2020 · 3 comments
Open

setSelectedIndex crash #166

npabion opened this issue Jun 20, 2020 · 3 comments

Comments

@npabion
Copy link

npabion commented Jun 20, 2020

If the spinner uses a selected text formatter with a type, calling setSelectedIndex crashes:

java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Locale
        ...
        at org.angmarch.views.NiceSpinner.setTextInternal(NiceSpinner.java:307)
        at org.angmarch.views.NiceSpinner.setSelectedIndex(NiceSpinner.java:323)

Example:

val textFormatter: SpinnerTextFormatter<Locale> = SpinnerTextFormatter<Locale> {
            locale -> SpannableString(locale.getDisplayName(defaultLocale))
}

view.locale_spinner.setSpinnerTextFormatter(textFormatter)
view.locale_spinner.setSelectedTextFormatter(textFormatter)
view.locale_spinner.attachDataSource(locales)
view.locale_spinner.selectedIndex = someIndex

The problem is setSelectedIndex calls setTextInternal(selectedTextFormatter.format(adapter.getItemInDataset(position)).toString()); which then calls setText(selectedTextFormatter.format(item)); but item is already a string and not the expected type.

@nocrisis
Copy link

nocrisis commented Dec 3, 2020

METOO

@fanqGithub
Copy link

代码下下来,修改下setTextInternal

@nocrisis
Copy link

代码下下来,修改下setTextInternal

修改成什么

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants