AutoCompleteTextView


public class AutoCompleteTextView
extends EditText implements Filter.FilterListener

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ android.widget.EditText
         ↳ android.widget.AutoCompleteTextView


An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.

The drop down can be dismissed at any time by pressing the back key or, if no item is selected in the drop down, by pressing the enter/dpad center key.

The list of suggestions is obtained from a data adapter and appears only after a given number of characters defined by the threshold.

The following code snippet shows how to create a text view which suggests various countries names while the user is typing:

 public class CountriesActivity extends Activity {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         setContentView(R.layout.countries);

         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                 android.R.layout.simple_dropdown_item_1line, COUNTRIES);
         AutoCompleteTextView textView = (AutoCompleteTextView)
                 findViewById(R.id.countries_list);
         textView.setAdapter(adapter);
     }

     private static final String[] COUNTRIES = new String[] {
         "Belgium", "France", "Italy", "Germany", "Spain"
     };
 }
 

See the Text Fields guide.

Summary

Nested classes

interface AutoCompleteTextView.OnDismissListener

Listener to respond to the AutoCompleteTextView's completion list being dismissed. 

interface AutoCompleteTextView.Validator

This interface is used to make sure that the text entered in this TextView complies to a certain format. 

XML attributes

android:completionHint Defines the hint displayed in the drop down menu. 
android:completionHintView Defines the hint view displayed in the drop down menu. 
android:completionThreshold Defines the number of characters that the user must type before completion suggestions are displayed in a drop down menu. 
android:dropDownAnchor View to anchor the auto-complete dropdown to. 
android:dropDownHeight Specifies the basic height of the dropdown. 
android:dropDownHorizontalOffset Amount of pixels by which the drop down should be offset horizontally. 
android:dropDownSelector Selector in a drop down list. 
android:dropDownVerticalOffset Amount of pixels by which the drop down should be offset vertically. 
android:dropDownWidth Specifies the basic width of the dropdown. 
android:popupBackground The background to use for the popup window. 

Inherited XML attributes

Inherited constants

Inherited fields

Public constructors

AutoCompleteTextView(Context context)

Constructs a new auto-complete text view with the given context's theme.

AutoCompleteTextView(Context context, AttributeSet attrs)

Constructs a new auto-complete text view with the given context's theme and the supplied attribute set.

AutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr)

Constructs a new auto-complete text view with the given context's theme, the supplied attribute set, and default style attribute.

AutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Constructs a new auto-complete text view with the given context's theme, the supplied attribute set, and default styles.

AutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, Resources.Theme popupTheme)

Constructs a new auto-complete text view with the given context, the supplied attribute set, default styles, and the theme against which the completion popup should be inflated.

Public methods

void clearListSelection()

Clear the list selection.

void dismissDropDown()

Closes the drop down if present on screen.

boolean enoughToFilter()

Returns true if the amount of text in the field meets or exceeds the getThreshold() requirement.

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.

ListAdapter getAdapter()

Returns a filterable list adapter used for auto completion.

CharSequence getCompletionHint()

Gets the optional hint text displayed at the bottom of the the matching list.

int getDropDownAnchor()

Returns the id for the view that the auto-complete drop down list is anchored to.

Drawable getDropDownBackground()

Gets the background of the auto-complete drop-down list.

int getDropDownHeight()

Returns the current height for the auto-complete drop down list.

int getDropDownHorizontalOffset()

Gets the horizontal offset used for the auto-complete drop-down list.

int getDropDownVerticalOffset()

Gets the vertical offset used for the auto-complete drop-down list.

int getDropDownWidth()

Returns the current width for the auto-complete drop down list.

int getInputMethodMode()

Returns the input method mode used by the auto complete dropdown.

AdapterView.OnItemClickListener getItemClickListener()

This method was deprecated in API level 15. Use getOnItemClickListener() intead

AdapterView.OnItemSelectedListener getItemSelectedListener()

This method was deprecated in API level 15. Use getOnItemSelectedListener() intead

int getListSelection()

Get the position of the dropdown view selection, if there is one.

AdapterView.OnItemClickListener getOnItemClickListener()

Returns the listener that is notified whenever the user clicks an item in the drop down list.

AdapterView.OnItemSelectedListener getOnItemSelectedListener()

Returns the listener that is notified whenever the user selects an item in the drop down list.

int getThreshold()

Returns the number of characters the user must type before the drop down list is shown.

AutoCompleteTextView.Validator getValidator()

Returns the Validator set with setValidator(Validator), or null if it was not set.

boolean isPerformingCompletion()

Identifies whether the view is currently performing a text completion, so subclasses can decide whether to respond to text changed events.

boolean isPopupShowing()

Indicates whether the popup menu is showing.

void onCommitCompletion(CompletionInfo completion)

Called by the framework in response to a text completion from the current input method, provided by it calling InputConnection.commitCompletion().

void onFilterComplete(int count)

Notifies the end of a filtering operation.

boolean onKeyDown(int keyCode, KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KeyEvent#KEYCODE_DPAD_CENTER or KeyEvent#KEYCODE_ENTER is released, if the view is enabled and clickable.

boolean onKeyPreIme(int keyCode, KeyEvent event)

Handle a key event before it is processed by any input method associated with the view hierarchy.

boolean onKeyUp(int keyCode, KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyUp(): perform clicking of the view when KeyEvent#KEYCODE_DPAD_CENTER, KeyEvent#KEYCODE_ENTER or KeyEvent#KEYCODE_SPACE is released.

void onWindowFocusChanged(boolean hasWindowFocus)

Called when the window containing this view gains or loses focus.

void performCompletion()

Performs the text completion by converting the selected item from the drop down list into a string, replacing the text box's content with this string and finally dismissing the drop down menu.

void performValidation()

If a validator was set on this view and the current string is not valid, ask the validator to fix it.

final void refreshAutoCompleteResults()

Refreshes the auto complete results.

<T extends ListAdapter & Filterable> void setAdapter(T adapter)

Changes the list of data used for auto completion.

void setCompletionHint(CharSequence hint)

Sets the optional hint text that is displayed at the bottom of the the matching list.

void setDropDownAnchor(int id)

Sets the view to which the auto-complete drop down list should anchor.

void setDropDownBackgroundDrawable(Drawable d)

Sets the background of the auto-complete drop-down list.

void setDropDownBackgroundResource(int id)

Sets the background of the auto-complete drop-down list.

void setDropDownHeight(int height)

Sets the current height for the auto-complete drop down list.

void setDropDownHorizontalOffset(int offset)

Sets the horizontal offset used for the auto-complete drop-down list.

void setDropDownVerticalOffset(int offset)

Sets the vertical offset used for the auto-complete drop-down list.

void setDropDownWidth(int width)

Sets the current width for the auto-complete drop down list.

void setInputMethodMode(int mode)

Use this method to specify when the IME should be displayed.

void setListSelection(int position)

Set the position of the dropdown view selection.

void setOnClickListener(View.OnClickListener listener)

Register a callback to be invoked when this view is clicked.

void setOnDismissListener(AutoCompleteTextView.OnDismissListener dismissListener)

Set a listener that will be invoked whenever the AutoCompleteTextView's list of completions is dismissed.

void setOnItemClickListener(AdapterView.OnItemClickListener l)

Sets the listener that will be notified when the user clicks an item in the drop down list.

void setOnItemSelectedListener(AdapterView.OnItemSelectedListener l)

Sets the listener that will be notified when the user selects an item in the drop down list.

void setText(CharSequence text, boolean filter)

Like TextView.setText(java.lang.CharSequence), except that it can disable filtering.

void setThreshold(int threshold)

Specifies the minimum number of characters the user has to type in the edit box before the drop down list is shown.

void setValidator(AutoCompleteTextView.Validator validator)

Sets the validator used to perform text validation.

void showDropDown()

Displays the drop down on screen.

Protected methods

CharSequence convertSelectionToString(Object selectedItem)

Converts the selected item from the drop down list into a sequence of character that can be used in the edit box.

Filter getFilter()

Returns the Filter obtained from Filterable#getFilter, or null if setAdapter(T) was not called with a Filterable.

void onAttachedToWindow()

This is called when the view is attached to a window.

void onDetachedFromWindow()

This is called when the view is detached from a window.

void onDisplayHint(int hint)

Gives this view a hint about whether is displayed or not.

void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect)

Called by the view system when the focus state of this view changes.

void performFiltering(CharSequence text, int keyCode)

Starts filtering the content of the drop down list.

void replaceText(CharSequence text)

Performs the text completion by replacing the current text by the selected item.

boolean setFrame(int l, int t, int r, int b)

Inherited methods

XML attributes

android:completionHint

Defines the hint displayed in the drop down menu.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

Related methods:

android:completionHintView

Defines the hint view displayed in the drop down menu.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:completionThreshold

Defines the number of characters that the user must type before completion suggestions are displayed in a drop down menu.

May be an integer value, such as "100".

Related methods:

android:dropDownAnchor

View to anchor the auto-complete dropdown to. If not specified, the text view itself is used.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

Related methods:

android:dropDownHeight

Specifies the basic height of the dropdown. Its value may be a dimension (such as "12dip") for a constant height, fill_parent or match_parent to fill the height of the screen, or wrap_content to match the height of the content of the drop down.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

Must be one of the following constant values.

ConstantValueDescription
fill_parentffffffffThe dropdown should fit the height of the screen. This constant is deprecated starting from API Level 8 and is replaced by match_parent.
match_parentffffffffThe dropdown should fit the height of the screen. Introduced in API Level 8.
wrap_contentfffffffeThe dropdown should fit the height of the content.

Related methods:

android:dropDownHorizontalOffset

Amount of pixels by which the drop down should be offset horizontally.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

Related methods:

android:dropDownSelector

Selector in a drop down list.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

android:dropDownVerticalOffset

Amount of pixels by which the drop down should be offset vertically.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

Related methods:

android:dropDownWidth

Specifies the basic width of the dropdown. Its value may be a dimension (such as "12dip") for a constant width, fill_parent or match_parent to match the width of the screen, or wrap_content to match the width of the anchored view.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

Must be one of the following constant values.

ConstantValueDescription
fill_parentffffffffThe dropdown should fill the width of the screen. This constant is deprecated starting from API Level 8 and is replaced by match_parent.
match_parentffffffffThe dropdown should fit the width of the screen. Introduced in API Level 8.
wrap_contentfffffffeThe dropdown should fit the width of its anchor.

Related methods:

android:popupBackground

The background to use for the popup window.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

Related methods:

Public constructors

AutoCompleteTextView

Added in API level 1
public AutoCompleteTextView (Context context)

Constructs a new auto-complete text view with the given context's theme.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.

AutoCompleteTextView

Added in API level 1
public AutoCompleteTextView (Context context, 
                AttributeSet attrs)

Constructs a new auto-complete text view with the given context's theme and the supplied attribute set.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.

attrs AttributeSet: The attributes of the XML tag that is inflating the view.

AutoCompleteTextView

Added in API level 1
public AutoCompleteTextView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Constructs a new auto-complete text view with the given context's theme, the supplied attribute set, and default style attribute.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.

attrs AttributeSet: The attributes of the XML tag that is inflating the view.

defStyleAttr int: An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults.

AutoCompleteTextView

Added in API level 21
public AutoCompleteTextView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Constructs a new auto-complete text view with the given context's theme, the supplied attribute set, and default styles.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.

attrs AttributeSet: The attributes of the XML tag that is inflating the view.

defStyleAttr int: An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults.

defStyleRes int: A resource identifier of a style resource that supplies default values for the view, used only if defStyleAttr is 0 or can not be found in the theme. Can be 0 to not look for defaults.

AutoCompleteTextView

Added in API level 24
public AutoCompleteTextView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes, 
                Resources.Theme popupTheme)

Constructs a new auto-complete text view with the given context, the supplied attribute set, default styles, and the theme against which the completion popup should be inflated.

Parameters
context Context: The context against which the view is inflated, which provides access to the current theme, resources, etc.

attrs AttributeSet: The attributes of the XML tag that is inflating the view.

defStyleAttr int: An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults.

defStyleRes int: A resource identifier of a style resource that supplies default values for the view, used only if defStyleAttr is 0 or can not be found in the theme. Can be 0 to not look for defaults.

popupTheme Resources.Theme: The theme against which the completion popup window should be inflated. May be null to use the view theme. If set, this will override any value specified by R.styleable.AutoCompleteTextView_popupTheme.

Public methods

clearListSelection

Added in API level 3
public void clearListSelection ()

Clear the list selection. This may only be temporary, as user input will often bring it back.

dismissDropDown

Added in API level 1
public void dismissDropDown ()

Closes the drop down if present on screen.

enoughToFilter

Added in API level 1
public boolean enoughToFilter ()

Returns true if the amount of text in the field meets or exceeds the getThreshold() requirement. You can override this to impose a different standard for when filtering will be triggered.

Returns
boolean

getAccessibilityClassName

Added in API level 23
public CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

getAdapter

Added in API level 1
public ListAdapter getAdapter ()

Returns a filterable list adapter used for auto completion.

Returns
ListAdapter a data adapter used for auto completion

getCompletionHint

Added in API level 16
public CharSequence getCompletionHint ()

Gets the optional hint text displayed at the bottom of the the matching list.

Related XML Attributes:

Returns
CharSequence The hint text, if any

getDropDownAnchor

Added in API level 3
public int getDropDownAnchor ()

Returns the id for the view that the auto-complete drop down list is anchored to.

Related XML Attributes:

Returns
int the view's id, or View#NO_ID if none specified

getDropDownBackground

Added in API level 5
public Drawable getDropDownBackground ()

Gets the background of the auto-complete drop-down list.

Related XML Attributes:

Returns
Drawable the background drawable

getDropDownHeight

Added in API level 4
public int getDropDownHeight ()

Returns the current height for the auto-complete drop down list. This can be a fixed width, or ViewGroup.LayoutParams.MATCH_PARENT to fill the screen, or ViewGroup.LayoutParams.WRAP_CONTENT to fit the width of its anchor view.

Related XML Attributes:

Returns
int the height for the drop down list

getDropDownHorizontalOffset

Added in API level 5
public int getDropDownHorizontalOffset ()

Gets the horizontal offset used for the auto-complete drop-down list.

Related XML Attributes:

Returns
int the horizontal offset

getDropDownVerticalOffset

Added in API level 5
public int getDropDownVerticalOffset ()

Gets the vertical offset used for the auto-complete drop-down list.

Related XML Attributes:

Returns
int the vertical offset

getDropDownWidth

Added in API level 3
public int getDropDownWidth ()

Returns the current width for the auto-complete drop down list. This can be a fixed width, or ViewGroup.LayoutParams.MATCH_PARENT to fill the screen, or ViewGroup.LayoutParams.WRAP_CONTENT to fit the width of its anchor view.

Related XML Attributes:

Returns
int the width for the drop down list

getInputMethodMode

Added in API level 29
public int getInputMethodMode ()

Returns the input method mode used by the auto complete dropdown.

Returns
int Value is ListPopupWindow.INPUT_METHOD_FROM_FOCUSABLE, ListPopupWindow.INPUT_METHOD_NEEDED, or ListPopupWindow.INPUT_METHOD_NOT_NEEDED

getItemClickListener

Added in API level 1
Deprecated in API level 15
public AdapterView.OnItemClickListener getItemClickListener ()

This method was deprecated in API level 15.
Use getOnItemClickListener() intead

Returns the listener that is notified whenever the user clicks an item in the drop down list.

Returns
AdapterView.OnItemClickListener the item click listener

getItemSelectedListener

Added in API level 1
Deprecated in API level 15
public AdapterView.OnItemSelectedListener getItemSelectedListener ()

This method was deprecated in API level 15.
Use getOnItemSelectedListener() intead

Returns the listener that is notified whenever the user selects an item in the drop down list.

Returns
AdapterView.OnItemSelectedListener the item selected listener

getListSelection

Added in API level 3
public int getListSelection ()

Get the position of the dropdown view selection, if there is one. Returns ListView.INVALID_POSITION if there is no dropdown or if there is no selection.

Returns
int the position of the current selection, if there is one, or ListView.INVALID_POSITION if not.

getOnItemClickListener

Added in API level 3
public AdapterView.OnItemClickListener getOnItemClickListener ()

Returns the listener that is notified whenever the user clicks an item in the drop down list.

Returns
AdapterView.OnItemClickListener the item click listener

getOnItemSelectedListener

Added in API level 3
public AdapterView.OnItemSelectedListener getOnItemSelectedListener ()

Returns the listener that is notified whenever the user selects an item in the drop down list.

Returns
AdapterView.OnItemSelectedListener the item selected listener

getThreshold

Added in API level 1
public int getThreshold ()

Returns the number of characters the user must type before the drop down list is shown.

Related XML Attributes:

Returns
int the minimum number of characters to type to show the drop down

See also:

getValidator

Added in API level 1
public AutoCompleteTextView.Validator getValidator ()

Returns the Validator set with setValidator(Validator), or null if it was not set.

Returns
AutoCompleteTextView.Validator

isPerformingCompletion

Added in API level 3
public boolean isPerformingCompletion ()

Identifies whether the view is currently performing a text completion, so subclasses can decide whether to respond to text changed events.

Returns
boolean

isPopupShowing

Added in API level 1
public boolean isPopupShowing ()

Indicates whether the popup menu is showing.

Returns
boolean true if the popup menu is showing, false otherwise

onCommitCompletion

Added in API level 3
public void onCommitCompletion (CompletionInfo completion)

Called by the framework in response to a text completion from the current input method, provided by it calling InputConnection.commitCompletion(). The default implementation does nothing; text views that are supporting auto-completion should override this to do their desired behavior.

Parameters
completion CompletionInfo: The auto complete text the user has selected.

onFilterComplete

Added in API level 1
public void onFilterComplete (int count)

Notifies the end of a filtering operation.

Parameters
count int: the number of values computed by the filter

onKeyDown

Added in API level 1
public boolean onKeyDown (int keyCode, 
                KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KeyEvent#KEYCODE_DPAD_CENTER or KeyEvent#KEYCODE_ENTER is released, if the view is enabled and clickable.

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters
keyCode int: a key code that represents the button pressed, from KeyEvent

event KeyEvent: the KeyEvent object that defines the button action

Returns
boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyPreIme

Added in API level 3
public boolean onKeyPreIme (int keyCode, 
                KeyEvent event)

Handle a key event before it is processed by any input method associated with the view hierarchy. This can be used to intercept key events in special situations before the IME consumes them; a typical example would be handling the BACK key to update the application's UI instead of allowing the IME to see it and close itself. Due to a bug, this function is not called for BACK key events on Android T and U, when the IME is shown.

Parameters
keyCode int: The value in event.getKeyCode().

event KeyEvent: Description of the key event.

Returns
boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyUp

Added in API level 1
public boolean onKeyUp (int keyCode, 
                KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyUp(): perform clicking of the view when KeyEvent#KEYCODE_DPAD_CENTER, KeyEvent#KEYCODE_ENTER or KeyEvent#KEYCODE_SPACE is released.

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters
keyCode int: A key code that represents the button pressed, from KeyEvent.

event KeyEvent: The KeyEvent object that defines the button action.

Returns
boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onWindowFocusChanged

Added in API level 1
public void onWindowFocusChanged (boolean hasWindowFocus)

Called when the window containing this view gains or loses focus. Note that this is separate from view focus: to receive key events, both your view and its window must have focus. If a window is displayed on top of yours that takes input focus, then your own window will lose focus but the view focus will remain unchanged.

Parameters
hasWindowFocus boolean: True if the window containing this view now has focus, false otherwise.

performCompletion

Added in API level 1
public void performCompletion ()

Performs the text completion by converting the selected item from the drop down list into a string, replacing the text box's content with this string and finally dismissing the drop down menu.

performValidation

Added in API level 1
public void performValidation ()

If a validator was set on this view and the current string is not valid, ask the validator to fix it.

refreshAutoCompleteResults

Added in API level 29
public final void refreshAutoCompleteResults ()

Refreshes the auto complete results. You usually shouldn't have to manually refresh the AutoCompleteResults as this is done automatically whenever the text changes. However if the results are not available and have to be fetched, you can call this function after fetching the results.

setAdapter

Added in API level 1
public void setAdapter (T adapter)

Changes the list of data used for auto completion. The provided list must be a filterable list adapter.

The caller is still responsible for managing any resources used by the adapter. Notably, when the AutoCompleteTextView is closed or released, the adapter is not notified. A common case is the use of CursorAdapter, which contains a Cursor that must be closed. This can be done automatically (see startManagingCursor()), or by manually closing the cursor when the AutoCompleteTextView is dismissed.

Parameters
adapter T: the adapter holding the auto completion data

setCompletionHint

Added in API level 1
public void setCompletionHint (CharSequence hint)

Sets the optional hint text that is displayed at the bottom of the the matching list. This can be used as a cue to the user on how to best use the list, or to provide extra information.

Related XML Attributes:

Parameters
hint CharSequence: the text to be displayed to the user

setDropDownAnchor

Added in API level 3
public void setDropDownAnchor (int id)

Sets the view to which the auto-complete drop down list should anchor. The view corresponding to this id will not be loaded until the next time it is needed to avoid loading a view which is not yet instantiated.

Related XML Attributes:

Parameters
id int: the id to anchor the drop down list view to

setDropDownBackgroundDrawable

Added in API level 5
public void setDropDownBackgroundDrawable (Drawable d)

Sets the background of the auto-complete drop-down list.

Related XML Attributes:

Parameters
d Drawable: the drawable to set as the background

setDropDownBackgroundResource

Added in API level 5
public void setDropDownBackgroundResource (int id)

Sets the background of the auto-complete drop-down list.

Related XML Attributes:

Parameters
id int: the id of the drawable to set as the background

setDropDownHeight

Added in API level 4
public void setDropDownHeight (int height)

Sets the current height for the auto-complete drop down list. This can be a fixed width, or ViewGroup.LayoutParams.MATCH_PARENT to fill the screen, or ViewGroup.LayoutParams.WRAP_CONTENT to fit the width of its anchor view.

Related XML Attributes:

Parameters
height int: the height to use

setDropDownHorizontalOffset

Added in API level 5
public void setDropDownHorizontalOffset (int offset)

Sets the horizontal offset used for the auto-complete drop-down list.

Related XML Attributes:

Parameters
offset int: the horizontal offset

setDropDownVerticalOffset

Added in API level 5
public void setDropDownVerticalOffset (int offset)

Sets the vertical offset used for the auto-complete drop-down list.

Related XML Attributes:

Parameters
offset int: the vertical offset

setDropDownWidth

Added in API level 3
public void setDropDownWidth (int width)

Sets the current width for the auto-complete drop down list. This can be a fixed width, or ViewGroup.LayoutParams.MATCH_PARENT to fill the screen, or ViewGroup.LayoutParams.WRAP_CONTENT to fit the width of its anchor view.

Related XML Attributes:

Parameters
width int: the width to use

setInputMethodMode

Added in API level 29
public void setInputMethodMode (int mode)

Use this method to specify when the IME should be displayed. This function can be used to prevent the dropdown from obscuring the IME.

Parameters
mode int: speficies the input method mode. use one of the following values: ListPopupWindow#INPUT_METHOD_FROM_FOCUSABLE IME Displayed if the auto-complete box is focusable. ListPopupWindow#INPUT_METHOD_NEEDED Always display the IME. ListPopupWindow#INPUT_METHOD_NOT_NEEDED. The auto-complete suggestions are always displayed, even if the suggestions cover/hide the input method. Value is ListPopupWindow.INPUT_METHOD_FROM_FOCUSABLE, ListPopupWindow.INPUT_METHOD_NEEDED, or ListPopupWindow.INPUT_METHOD_NOT_NEEDED

setListSelection

Added in API level 3
public void setListSelection (int position)

Set the position of the dropdown view selection.

Parameters
position int: The position to move the selector to.

setOnClickListener

Added in API level 1
public void setOnClickListener (View.OnClickListener listener)

Register a callback to be invoked when this view is clicked. If this view is not clickable, it becomes clickable.

Parameters
listener View.OnClickListener: The callback that will run This value may be null.

setOnDismissListener

Added in API level 17
public void setOnDismissListener (AutoCompleteTextView.OnDismissListener dismissListener)

Set a listener that will be invoked whenever the AutoCompleteTextView's list of completions is dismissed.

Parameters
dismissListener AutoCompleteTextView.OnDismissListener: Listener to invoke when completions are dismissed

setOnItemClickListener

Added in API level 1
public void setOnItemClickListener (AdapterView.OnItemClickListener l)

Sets the listener that will be notified when the user clicks an item in the drop down list.

Parameters
l AdapterView.OnItemClickListener: the item click listener

setOnItemSelectedListener

Added in API level 1
public void setOnItemSelectedListener (AdapterView.OnItemSelectedListener l)

Sets the listener that will be notified when the user selects an item in the drop down list.

Parameters
l AdapterView.OnItemSelectedListener: the item selected listener

setText

Added in API level 17
public void setText (CharSequence text, 
                boolean filter)

Like TextView.setText(java.lang.CharSequence), except that it can disable filtering.

Parameters
text CharSequence

filter boolean: If false, no filtering will be performed as a result of this call.

setThreshold

Added in API level 1
public void setThreshold (int threshold)

Specifies the minimum number of characters the user has to type in the edit box before the drop down list is shown.

When threshold is less than or equals 0, a threshold of 1 is applied.

Related XML Attributes:

Parameters
threshold int: the number of characters to type before the drop down is shown

See also:

setValidator

Added in API level 1
public void setValidator (AutoCompleteTextView.Validator validator)

Sets the validator used to perform text validation.

Parameters
validator AutoCompleteTextView.Validator: The validator used to validate the text entered in this widget.

showDropDown

Added in API level 1
public void showDropDown ()

Displays the drop down on screen.

Protected methods

convertSelectionToString

Added in API level 1
protected CharSequence convertSelectionToString (Object selectedItem)

Converts the selected item from the drop down list into a sequence of character that can be used in the edit box.

Parameters
selectedItem Object: the item selected by the user for completion

Returns
CharSequence a sequence of characters representing the selected suggestion

getFilter

Added in API level 1
protected Filter getFilter ()

Returns the Filter obtained from Filterable#getFilter, or null if setAdapter(T) was not called with a Filterable.

Returns
Filter

onAttachedToWindow

Added in API level 1
protected void onAttachedToWindow ()

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).
If you override this method you must call through to the superclass implementation.

onDetachedFromWindow

Added in API level 1
protected void onDetachedFromWindow ()

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.
If you override this method you must call through to the superclass implementation.

onDisplayHint

Added in API level 8
protected void onDisplayHint (int hint)

Gives this view a hint about whether is displayed or not. For instance, when a View moves out of the screen, it might receives a display hint indicating the view is not displayed. Applications should not rely on this hint as there is no guarantee that they will receive one.

Parameters
hint int: A hint about whether or not this view is displayed: View.VISIBLE or View.INVISIBLE. Value is View.VISIBLE, View.INVISIBLE, or View.GONE

onFocusChanged

Added in API level 1
protected void onFocusChanged (boolean focused, 
                int direction, 
                Rect previouslyFocusedRect)

Called by the view system when the focus state of this view changes. When the focus change event is caused by directional navigation, direction and previouslyFocusedRect provide insight into where the focus is coming from. When overriding, be sure to call up through to the super class so that the standard focus handling will occur.
If you override this method you must call through to the superclass implementation.

Parameters
focused boolean: True if the View has focus; false otherwise.

direction int: The direction focus has moved when requestFocus() is called to give this view focus. Values are View.FOCUS_UP, View.FOCUS_DOWN, View.FOCUS_LEFT, View.FOCUS_RIGHT, View.FOCUS_FORWARD, or View.FOCUS_BACKWARD. It may not always apply, in which case use the default. Value is View.FOCUS_BACKWARD, View.FOCUS_FORWARD, View.FOCUS_LEFT, View.FOCUS_UP, View.FOCUS_RIGHT, or View.FOCUS_DOWN

previouslyFocusedRect Rect: The rectangle, in this view's coordinate system, of the previously focused view. If applicable, this will be passed in as finer grained information about where the focus is coming from (in addition to direction). Will be null otherwise.

performFiltering

Added in API level 1
protected void performFiltering (CharSequence text, 
                int keyCode)

Starts filtering the content of the drop down list. The filtering pattern is the content of the edit box. Subclasses should override this method to filter with a different pattern, for instance a substring of text.

Parameters
text CharSequence: the filtering pattern

keyCode int: the last character inserted in the edit box; beware that this will be null when text is being added through a soft input method.

replaceText

Added in API level 1
protected void replaceText (CharSequence text)

Performs the text completion by replacing the current text by the selected item. Subclasses should override this method to avoid replacing the whole content of the edit box.

Parameters
text CharSequence: the selected suggestion in the drop down list

setFrame

Added in API level 1
protected boolean setFrame (int l, 
                int t, 
                int r, 
                int b)

Parameters
l int

t int

r int

b int

Returns
boolean