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

setSelectedIndex crash #166

@npabion

Description

@npabion

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions