nice-spinner icon indicating copy to clipboard operation
nice-spinner copied to clipboard

Find a bug ClassCastException

Open FlodCoding opened this issue 5 years ago • 1 comments

this is my code

`spinnerType.setSpinnerTextFormatter((SpinnerTextFormatter<Map.Entry<String, String>>) item -> new SpannableString(item.getKey())); spinnerType.setSelectedTextFormatter((SpinnerTextFormatter<Map.Entry<String, String>>) item -> new SpannableString(item.getKey()));

    spinnerType.setOnSpinnerItemSelectedListener((parent, view, position, id) -> {
                mPageIndex = 1;
                mType = ((Map.Entry<String, String>) parent.getSelectedItem()).getValue();
                mPresenter.getFundFlowRecord(false, mType, mStatus, tvStartTime.getText().toString(),
                        tvEndTime.getText().toString(), mPageIndex, true);
            }
    );`

but when I select spinner index it will be crash:

spinnerType.setSelectedIndex(selectIndex);

: Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map$Entry

I look you code and find this:

https://github.com/arcadefire/nice-spinner/blob/f1bc07f83dbd24ea5aa9c20915a9b457a6dccd99/library/src/main/java/org/angmarch/views/NiceSpinner.java#L323

setTextInternal https://github.com/arcadefire/nice-spinner/blob/f1bc07f83dbd24ea5aa9c20915a9b457a6dccd99/library/src/main/java/org/angmarch/views/NiceSpinner.java#L307

I think you format selectedText double time, right?

FlodCoding avatar Jul 10 '19 14:07 FlodCoding

Yep I can confirm this. A temporary fix is to remove all formatters and override toString() method on your custom object, making it return what you want to show on the spinner.

gpallas16 avatar Aug 08 '19 22:08 gpallas16