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] Pop up menu calls adapter.getView(), not adapter.getDropDownView() #4374

Open
nikclayton opened this issue Nov 14, 2024 · 0 comments

Comments

@nikclayton
Copy link

Description:

When an adapter is set on an AutoCompleteTextView, the adapter's getView() method is called to get the view to show in the dropdown / popup menu. From the adapter documentation (e.g., on ArrayAdapter) I had expected getDropViewView() to be called.

Expected behavior:

getDropDownView() to be called. It is documented as:

Gets a View that displays in the drop down popup the data at the specified position in the data set.

where as getView() is documented as:

Get a View that displays the data at the specified position in the data set.

Since I'm using AutoCompleteTextView in an exposed dropdown menu (https://github.com/material-components/material-components-android/blob/master/docs/components/Menu.md#exposed-dropdown-menu-example) I expected the method with dropdown in the name to be called.

It's probably too late to change the code (outside of a breaking change release), but a very clear note in the documentation everywhere it demonstrates setting an adapter that getDropDownView is ignored would be helpful.

Source code:

val items = listOf("Item 1", "Item 2", "Item 3", "Item 4")
val adapter = object : ArrayAdapter(requireContext(), android.R.layout.simple_list_item_1, items) {
    init {
        setDropDownViewResource(android.R.layout.simple_list_item_2)
    }

    override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
        // bind data to the UI here, populating the second textview in layout.simple_list_item_2
    }
}
(textField.editText as? AutoCompleteTextView)?.setAdapter(adapter)

Instrumenting getDropDownView and getView with logging calls quickly shows that only getView is called.

Android API version: 31

Material Library version: 1.12.0

Device: Emulator

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

2 participants