Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spinner shows package name #37

Open
mikelantzelo opened this issue Jan 15, 2021 · 2 comments
Open

Spinner shows package name #37

mikelantzelo opened this issue Jan 15, 2021 · 2 comments

Comments

@mikelantzelo
Copy link

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

@LunevNF
Copy link

LunevNF commented Jan 22, 2021

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

@AlfredAbdo
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants