MaterialSpinner
MaterialSpinner copied to clipboard
Spinner shows package name
Hi spinner shows package name when selecting an item. Can anyone help?
Same problem. Can customize the view for dropdown, but selected item - only package name and getView never called in adapter
0- The MaterialSpinner library is an awesome idea, especially if you rely on the concept of Live Validation (using setError for TextInputLayout, etc.). That allows the use of MaterialSpinner without handling Android's Spinner, and also makes it look very similar to the other TextInputLayouts in a form page.
Same problem. Can customize the view for dropdown, but selected item - only package name and getView never called in adapter
1- My solution to the spinner selected item problem was to introduce a new interface for the items (not practical, but that was my bypass for using MaterialSpinner):
interface MaterialSpinnerItem {
fun toSelectedString(): String
fun toDisplayString(): String = toSelectedString()
}
Then, inside selection
variable's setter (from line 127), add the MaterialSpinnerItem check for the 'editText.setText' clause:
editText.setText(
when (val item = getItem(value) ?: "") {
is CharSequence -> item
is MaterialSpinnerItem -> item.toSelectedString()
else -> item.toString()
}
)
Then, feel free to use toDisplayString() in your custom adapter for the dropdown (or the other popups).
2- Since the MaterialSpinner is not technically an Android Spinner, the ListAdapter is not used as it would be used with a Spinner. Remember, MaterialSpinner is a TextInputLayout, i.e. it is not straight-forward to create a custom view as you would with a Spinner: the adapter is only used for the popups, where only the dropdown version is used (and where you need to use it).
I could not find a good solution for this as I am not sure a TextInputLayout (or even a TextInputEditText) allows to properly inflate views.