Since c71b6ccb has been pushed to 1.1.0-alpha06, we finally have a nice dropdown menu, replacing Spinners with AutoCompleteTextView. It's a nice change, however I found a small issue with it while using databinding.
The following databinding extensions were used, with the layout:
https://gist.github.com/fonix232/6553f66d17746dca5d062eecf40e8b3b
It's a bit hackier than a regular Spinner, and if I do the same logic manually from the actual view, it works quite well. However in binding, it just fails miserably.
The above binding will display only one item in the drop down menu, the one selected (in fact I'm posting this after not having the null check in the selectedValue binding, which resulted in an empty, glitching list, and the value being permanently (null)). Unless I cycle through all the items manually upon binding the Adapter, the list stays empty, which is nuts.
What the hell is going wrong here? This binding should work even without the null checks, yet it doesn't. And the databinding execution context shouldn't be that different than calling the same stuff from the fragment's (technically, a Conductor controller's) onAttached method.
So I was trying to implement this as I was quite excited. Do you have a gist to how you made it work before the binding adapters?
As I said, I literally used the same calls:
fun onViewCreated(...) {
val binding = [inflate binding]
val adapter = ArrayAdapter(context, R.layout.item_dropdown, R.id.dropdownText, resources.getStringArray(R.array.genders))
binding.gender.setAdapter(adapter)
binding.gender.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {}
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
viewModel.gender.postValue(adapter.getItem(position))
}
}
}
We're investigating at http://issuetracker.google.com/132333967
This sounds like a completionThreshold bug I encountered as well. Within DropdownMenuEndIconDelegate the threshold is set to 0, which autocomplete sanitizes to 1. This meant that if you initialize the field with a value the dropdown will be filtered on that value.
I was able to work around the issue by setting a larger value using data binding which is processed after the view is created.
Here is my solution that I have working: https://gist.github.com/frett/d6a2dbdc9718444847d00768fbaeacf5
Not sure if I understood your issue properly but I had a similar issue with AutoCompleteTextView after programatically setting it's text.
My AutoCompleteTextView adapter was pointing to an array with 3 values and I wanted to select a value by default when loading the view so I used the setText(string text) method.
The issue in my case was that once I did: autoCompleteTextView.setText("value1") then from the UI when I was opening the dropdown to select another value there was only one option in the list ("value1").
After some googling I found out that AutoCompleteTextView has a setText method that accepts a boolean parameter: settext(string text, boolean filter) and by setting the filter to false I had access to all the values one again. Maybe it helps you too.
Not sure if I understood your issue properly but I had a similar issue with AutoCompleteTextView after programatically setting it's text.
My AutoCompleteTextView adapter was pointing to an array with 3 values and I wanted to select a value by default when loading the view so I used the setText(string text) method.
The issue in my case was that once I did: autoCompleteTextView.setText("value1") then from the UI when I was opening the dropdown to select another value there was only one option in the list ("value1").
After some googling I found out that AutoCompleteTextView has a setText method that accepts a boolean parameter: settext(string text, boolean filter) and by setting the filter to false I had access to all the values one again. Maybe it helps you too.
Thank you @adrian05. I also have that issue after calling setText() and I was exploring the issue for a couple days. Finally, you saved my day 馃槄
I have found a post that explains what the problems are - rant included. https://medium.com/@rmirabelle/there-is-no-material-design-spinner-for-android-3261b7c77da8
ExposedDropdownMenu please if any have do this example tell me how can i implement style on style xml file i have an error cannot resolve materialThemeOverlay , endIconMode i have copy that code on githubon material.io websites.
<item name="materialThemeOverlay">
@style/ThemeOverlay.MaterialComponents.AutoCompleteTextView.FilledBox
</item>
<item name="endIconMode">dropdown_menu</item>
</style>
Most helpful comment
Not sure if I understood your issue properly but I had a similar issue with AutoCompleteTextView after programatically setting it's text.
My AutoCompleteTextView adapter was pointing to an array with 3 values and I wanted to select a value by default when loading the view so I used the setText(string text) method.
The issue in my case was that once I did: autoCompleteTextView.setText("value1") then from the UI when I was opening the dropdown to select another value there was only one option in the list ("value1").
After some googling I found out that AutoCompleteTextView has a setText method that accepts a boolean parameter: settext(string text, boolean filter) and by setting the filter to false I had access to all the values one again. Maybe it helps you too.