material-components-android: [AutoCompleteTextView] Exposed Dropdown Menu not showing items
Description:
Exposed Dropdown Menu doesn’t show items after user selection and fragment transition.
Following is the basic xml declaration:
<com.google.android.material.textfield.TextInputLayout
...
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
<AutoCompleteTextView
....
android:id="@+id/dropdown"
android:dropDownHeight="300dp"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
And, the declared code on the fragment (inside onViewCreated()):
val items = listOf("Material", "Design", "Components", "Android")
val adapter = ArrayAdapter(requireContext(), R.layout.item_menu, items)
dropdown.setAdapter(adapter)
dropdown.setText(items[0], false)
As mentioned here, it was set on AutoCompleteTextView's setText method (dropdown.setText(“”, false)) the filter parameter as false. However, after navigating to a next fragment and coming back to it, only the pre-selected text is shown on the dropdown.
Fragments are changed using navigation component (v. 2.3.2).
Expected behavior: Dropdown should show all items.
Android API version: Android API 30
Material Library version: 1.3.0-rc01
Device: Emulator - Pixel 4 XL
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 21
- Comments: 19 (1 by maintainers)
You can implement this extention on onClickListener to make all list keep showing after it clicked.
And also add focusable=“false” to AutoCompleteTextView in xml.
Temp solution working for me is to move part of the code to onResume():
As of now (Sept 2023) this bug still exists in material 1.9
If it is in fragment you better put this extension in onResume, this way filters are canceled automatically.
This works perfectly, thank you !
Faced the same problem. Downgrading ‘androidx.navigation:navigation-ui-ktx’ library from 2.4.2 to version 2.3.5 helped me
Same problem on material version 1.4.0 had to implement custom array adapter with custom/no filter