public class

AutoCompleteTextView

extends EditText
implements Filter.FilterListener
java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ android.widget.EditText
         ↳ android.widget.AutoCompleteTextView
Known Direct Subclasses

Class Overview

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 Auto Complete tutorial.

Summary

Nested Classes
interface AutoCompleteTextView.Validator This interface is used to make sure that the text entered in this TextView complies to a certain format. 
XML Attributes
Attribute Name Related Method Description
android:completionHint setCompletionHint(CharSequence) Defines the hint displayed in the drop down menu. 
android:completionHintView Defines the hint view displayed in the drop down menu. 
android:completionThreshold setThreshold(int) Defines the number of characters that the user must type before completion suggestions are displayed in a drop down menu. 
android:dropDownAnchor setDropDownAnchor(int) View to anchor the auto-complete dropdown to. 
android:dropDownHeight setDropDownHeight(int) 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 setDropDownWidth(int) Specifies the basic width of the dropdown. 
android:popupBackground setDropDownBackgroundResource(int)  
[Expand]
Inherited XML Attributes
From class android.widget.TextView
From class android.view.View
[Expand]
Inherited Constants
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
AutoCompleteTextView(Context context)
AutoCompleteTextView(Context context, AttributeSet attrs)
AutoCompleteTextView(Context context, AttributeSet attrs, int defStyle)
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.
ListAdapter getAdapter()

Returns a filterable list adapter used for auto completion.

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.

AdapterView.OnItemClickListener getItemClickListener()
This method is deprecated. Use getOnItemClickListener() intead
AdapterView.OnItemSelectedListener getItemSelectedListener()
This method is deprecated. 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(AutoCompleteTextView.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 KEYCODE_DPAD_CENTER or 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 KEYCODE_DPAD_CENTER or KEYCODE_ENTER 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.
<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 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 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 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 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)
Assign a size and position to this view.
[Expand]
Inherited Methods
From class android.widget.EditText
From class android.widget.TextView
From class android.view.View