question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[AutoCompleteTextView] Exposed Dropdown Menu not showing items

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:19
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
heriawanfxcommented, Mar 28, 2021

You can implement this extention on onClickListener to make all list keep showing after it clicked.

fun AutoCompleteTextView.showDropdown(adapter: ArrayAdapter<String>?) {
    if(!TextUtils.isEmpty(this.text.toString())){
        adapter?.filter?.filter(null)
    }
}

And also add focusable=“false” to AutoCompleteTextView in xml.

3reactions
jerryOkaforcommented, Jun 25, 2021

Currently experiencing the same problem here, does any one have a fix for this?

Temp solution working for me is to move part of the code to onResume():

override fun onResume() {
        super.onResume()

        val arrayAdapter =
            ArrayAdapter(requireContext(), R.layout.menu_list_item, floorEntries)
        binding.tvFloor.setAdapter(arrayAdapter)

        setSelectedFloor()
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Exposed Dropdown Menu not showing items - Stack Overflow
Exposed Dropdown Menu doesn't show items after user selection and fragment transition. ... As mentioned here, it was set on AutoCompleteTextView's ...
Read more >
Autocompletetextview Dropdown Not Showing - ADocLib
Description: Exposed Dropdown Menu doesn't show items after user selection and fragment transition. Following is the basic xml declaration: I have tried hacks ......
Read more >
Exposed Drop-Down Menu in Android | by Emine İNAN
Create a new layout file called dropdown_item.xml and add a TextView that will represent a single item of the Exposed Drop-Down Menu.
Read more >
Menus – Material Design 3
Menus display a list of choices on a temporary surface. ... Types: Dropdown menu and exposed dropdown menu are now both referred to...
Read more >
Creating & styling dropdown menus on Android - ITNEXT
Exposed dropdown menus display the currently selected menu item above the ... that tells the AutoCompleteTextView that we're not planning on ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found