MaterialSpinner icon indicating copy to clipboard operation
MaterialSpinner copied to clipboard

Spinner shows package name

Open mikelantzelo opened this issue 4 years ago • 2 comments

Hi spinner shows package name when selecting an item. Can anyone help?

mikelantzelo avatar Jan 15 '21 08:01 mikelantzelo

Same problem. Can customize the view for dropdown, but selected item - only package name and getView never called in adapter

LunevNF avatar Jan 22 '21 11:01 LunevNF

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.

AlfredAbdo avatar Mar 23 '21 05:03 AlfredAbdo