material-components / material-components/material-components-android

[AutoCompleteTextView] Pop up menu calls `adapter.getView()`, not `adapter.getDropDownView()`

Open
#4,374 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Documentation Widget: TextView
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**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:**

```kotlin
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with docs/components/Menu.md and search the repository for AutoCompleteTextView examples that set an adapter. Verify the documented behavior against the issue's getView() and getDropDownView() observations, then add a clear note wherever relevant examples appear; done when users are told which method supplies the popup view.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.