{"record":{"id":"64446b1389f24175","repo":"material-components/material-components-android","slug":"edittext-needs-to-be-an-autocompletetextview-if-an","errorCode":null,"errorMessage":"EditText needs to be an AutoCompleteTextView if an Exposed Dropdown Menu is being used.","messagePattern":"EditText needs to be an AutoCompleteTextView if an Exposed Dropdown Menu is being used\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/textfield/DropdownMenuEndIconDelegate.java","lineNumber":291,"sourceCode":"      }\n      return false;\n    });\n    autoCompleteTextView.setOnDismissListener(() -> {\n      updateDropdownPopupDirty();\n      setEndIconChecked(false);\n    });\n    autoCompleteTextView.setThreshold(0);\n  }\n\n  private boolean isDropdownPopupActive() {\n    long activeFor = SystemClock.uptimeMillis() - dropdownPopupActivatedAt;\n    return activeFor < 0 || activeFor > 300;\n  }\n\n  @NonNull\n  private static AutoCompleteTextView castAutoCompleteTextViewOrThrow(EditText editText) {\n    if (!(editText instanceof AutoCompleteTextView)) {\n      throw new RuntimeException(\n          \"EditText needs to be an AutoCompleteTextView if an Exposed Dropdown Menu is being\"\n              + \" used.\");\n    }\n\n    return (AutoCompleteTextView) editText;\n  }\n\n  private void updateDropdownPopupDirty() {\n    dropdownPopupDirty = true;\n    dropdownPopupActivatedAt = SystemClock.uptimeMillis();\n  }\n\n  private void setEndIconChecked(boolean checked) {\n    if (isEndIconChecked != checked) {\n      isEndIconChecked = checked;\n      fadeInAnim.cancel();\n      fadeOutAnim.start();\n    }","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/textfield/DropdownMenuEndIconDelegate.java#L273-L309","documentation":"DropdownMenuEndIconDelegate powers the END_ICON_DROPDOWN_MENU end icon in a TextInputLayout. Its machinery (threshold, popup sync) only works on an AutoCompleteTextView, so when the layout's EditText is some other EditText subclass it throws a RuntimeException via castAutoCompleteTextViewOrThrow.","triggerScenarios":"Setting app:endIconMode=\"dropdown_menu\" (or setEndIconMode(END_ICON_DROPDOWN_MENU)) on a TextInputLayout whose TextInputEditText is a plain TextInputEditText or other non-AutoCompleteTextView; using the ExposedDropdownMenu style but keeping TextInputEditText as the inner edit field.","commonSituations":"Copy-pasting a filled/outlined TextInputLayout block and switching the style to ExposedDropdownMenu without swapping the inner view; mixing a custom EditText subclass with the dropdown end icon.","solutions":["Use an AutoCompleteTextView as the TextInputLayout's child, e.g. <AutoCompleteTextView style=\"@style/Widget.Material3.AutoCompleteTextView.OutlinedExposedDropdownMenu\"/> (or the M2 ExposedDropdownMenu equivalent).","Or use the ready-made style on the TextInputLayout: Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu.","If the field is not a dropdown, remove END_ICON_DROPDOWN_MENU and use another end icon mode."],"exampleFix":"<!-- before -->\n<com.google.android.material.textfield.TextInputLayout app:endIconMode=\"dropdown_menu\">\n  <com.google.android.material.textfield.TextInputEditText/>\n</com.google.android.material.textfield.TextInputLayout>\n\n<!-- after -->\n<com.google.android.material.textfield.TextInputLayout\n    style=\"@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu\">\n  <AutoCompleteTextView\n      style=\"@style/Widget.Material3.AutoCompleteTextView.OutlinedExposedDropdownMenu\"/>\n</com.google.android.material.textfield.TextInputLayout>","handlingStrategy":"type-guard","validationCode":"if (til.getEditText() instanceof android.widget.AutoCompleteTextView) {\n  til.setEndIconMode(TextInputLayout.END_ICON_DROPDOWN_MENU);\n} else {\n  // not a dropdown field: pick another end icon mode or fix the layout XML\n}","typeGuard":"private boolean supportsDropdownEndIcon(@NonNull TextInputLayout til) {\n  return til.getEditText() instanceof AutoCompleteTextView;\n}","tryCatchPattern":null,"preventionTips":["Pair app:endIconMode=\"dropdown_menu\" with an AutoCompleteTextView child.","Use the ExposedDropdownMenu styles as a matched set (layout + inner view).","Guard any dynamic setEndIconMode(DROPDOWN_MENU) with an instanceof check."],"tags":["textinputlayout","dropdown","type-mismatch","android"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}