Added in API level 1

AutoCompleteTextView


open class AutoCompleteTextView : EditText, Filter.FilterListener
kotlin.Any
   ↳ 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
abstract

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

abstract

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.
Inherited XML attributes
Inherited constants
Public constructors

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

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

AutoCompleteTextView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

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

AutoCompleteTextView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

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

AutoCompleteTextView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int, popupTheme: Resources.Theme!)

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
open Unit

Clear the list selection.

open Unit

Closes the drop down if present on screen.

open Boolean

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

open CharSequence!

open ListAdapter!

Returns a filterable list adapter used for auto completion.

open CharSequence!

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

open Int

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

open Drawable!

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

open Int

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

open Int

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

open Int

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

open Int

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

open Int

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

open AdapterView.OnItemClickListener!

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

open AdapterView.OnItemSelectedListener!

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

open Int

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

open AdapterView.OnItemClickListener!

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

open AdapterView.OnItemSelectedListener!

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

open Int

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

open AutoCompleteTextView.Validator!

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

open Boolean

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

open Boolean

Indicates whether the popup menu is showing.

open Unit

open Unit

Notifies the end of a filtering operation.

open Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)

open Boolean
onKeyPreIme(keyCode: Int, event: KeyEvent!)

open Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)

open Unit
onWindowFocusChanged(hasWindowFocus: Boolean)

open Unit

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.

open Unit

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

Unit

Refreshes the auto complete results.

open Unit
setAdapter(adapter: T)

Changes the list of data used for auto completion.

open Unit

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

open Unit

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

open Unit

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

open Unit

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

open Unit

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

open Unit

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

open Unit

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

open Unit

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

open Unit

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

open Unit
setListSelection(position: Int)

Set the position of the dropdown view selection.

open Unit

open Unit

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

open Unit

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

open Unit

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

open Unit
setText(text: CharSequence!, filter: Boolean)

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

open Unit
setThreshold(threshold: Int)

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

open Unit

Sets the validator used to perform text validation.

open Unit

Displays the drop down on screen.

Protected methods
open CharSequence!
convertSelectionToString(selectedItem: Any!)

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

open Filter!

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

open Unit

open Unit

open Unit

open Unit
onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?)

open Unit
performFiltering(text: CharSequence!, keyCode: Int)

Starts filtering the content of the drop down list.

open Unit

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

open Boolean
setFrame(l: Int, t: Int, r: Int, b: Int)

Inherited functions