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

[AutoCompleteTextView] Exposed Dropdown Menu not showing items #2012

Closed
philipbrito opened this issue Jan 28, 2021 · 20 comments
Closed

[AutoCompleteTextView] Exposed Dropdown Menu not showing items #2012

philipbrito opened this issue Jan 28, 2021 · 20 comments

Comments

@philipbrito
Copy link

philipbrito commented Jan 28, 2021

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

@mschief148
Copy link

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

@heriawanfx
Copy link

heriawanfx commented 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.

@jishindev
Copy link

Any update on this?

@AbdulazizRasulbek
Copy link

The same problem

@gson2019
Copy link

gson2019 commented Jun 7, 2021

Same problem seen, any updates ?

@amg
Copy link

amg commented Jun 16, 2021

same issue, in 1.4.0-rc01 as well

@amg
Copy link

amg commented Jun 16, 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.

This does seem to work as a temp workaround 🤔 🙏

@jerryOkafor
Copy link

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

@jerryOkafor
Copy link

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

@ghost
Copy link

ghost commented Aug 11, 2021

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

@olala2288
Copy link

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 worked for me if it got fixed just update this issue thanks

@Volua
Copy link

Volua commented Dec 18, 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.

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

@drchen
Copy link
Contributor

drchen commented Apr 13, 2022

It's a duplicate of #1464. Unfortunately it's an Android framework issue and I'm trying to push for a workaround on the Material side or AppCompat.

@drchen drchen closed this as completed Apr 13, 2022
@Leshachok
Copy link

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

@nadar71
Copy link

nadar71 commented Sep 6, 2022

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

@GentritIbishi
Copy link

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 !

@behelit
Copy link

behelit commented Dec 1, 2022

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

@RasulOs
Copy link

RasulOs commented Dec 19, 2022

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

@Sweeneyliu114514
Copy link

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

@EnriekNP
Copy link

EnriekNP commented Mar 21, 2024

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

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

No branches or pull requests