material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[AutoCompleteTextView] Exposed Dropdown Menu not showing items

Open philipbrito opened this issue 5 years ago • 20 comments

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

philipbrito avatar Jan 28 '21 03:01 philipbrito

I got the same problem, with setText("something", false) change the fragment and coming back only shows selected item on the list

mschief148 avatar Feb 26 '21 06:02 mschief148

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.

heriawanfx avatar Mar 28 '21 06:03 heriawanfx

Any update on this?

jishindev avatar May 28 '21 05:05 jishindev

The same problem

AbdulazizRasulbek avatar Jun 07 '21 14:06 AbdulazizRasulbek

Same problem seen, any updates ?

gson2019 avatar Jun 07 '21 15:06 gson2019

same issue, in 1.4.0-rc01 as well

amg avatar Jun 16 '21 04:06 amg

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.

This does seem to work as a temp workaround 🤔 🙏

amg avatar Jun 16 '21 05:06 amg

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

jerryOkafor avatar Jun 25 '21 03:06 jerryOkafor

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()
    }

jerryOkafor avatar Jun 25 '21 03:06 jerryOkafor

Same problem on material version 1.4.0 had to implement custom array adapter with custom/no filter

ghost avatar Aug 11 '21 11:08 ghost

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.

If it is in fragment you better put this extension in onResume, this way filters are canceled automatically.

Volua avatar Dec 18 '21 05:12 Volua

It's a duplicate of https://github.com/material-components/material-components-android/issues/1464. Unfortunately it's an Android framework issue and I'm trying to push for a workaround on the Material side or AppCompat.

drchen avatar Apr 13 '22 01:04 drchen

Faced the same problem. Downgrading 'androidx.navigation:navigation-ui-ktx' library from 2.4.2 to version 2.3.5 helped me

Leshachok avatar May 14 '22 11:05 Leshachok

Faced the same damn problem, here it solves putting all in onResume, as already written by someone else: https://www.youtube.com/watch?v=741l_fPKL3Y

nadar71 avatar Sep 06 '22 14:09 nadar71

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()
    }

This works perfectly, thank you !

GentritIbishi avatar Sep 07 '22 21:09 GentritIbishi

This is still a problem at 2022.12.01 using material:1.7.0 None of the workarounds appear to work in my case

behelit avatar Dec 01 '22 06:12 behelit

Same problem (material:1.4). The problem was solved by putting an ArrayAdapter in the onResume() method.

RasulOs avatar Dec 19 '22 06:12 RasulOs

As of now (Sept 2023) this bug still exists in material 1.9

Sweeneyliu114514 avatar Sep 08 '23 08:09 Sweeneyliu114514

this issue still happening for me... in material 1.10.0

EnriekNP avatar Mar 21 '24 02:03 EnriekNP

Still happening in material 1.12.0 😞

wanderdev0 avatar Mar 07 '25 23:03 wanderdev0