nice-spinner
nice-spinner copied to clipboard
Find a bug ClassCastException
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?
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.