Android AutoComplete TextView - Androhub

AutoComplete and MultiAutoComplete TextView

Android AutoComplete and MultiAutoComplete TextView

Android AutoCompleteTextView completes the word based on the reserved words, so no need to write all the characters of the word.

Android AutoCompleteTextView is a editable text field, it displays a list of suggestions in a drop down menu from which user can select only one suggestion or value.

Android AutoCompleteTextView is the subclass of EditText class. The MultiAutoCompleteTextView is the subclass of AutoCompleteTextView class.

There are some methods of AutoCompleteTextView listed below :

MethodDescription
getAdapter()This method returns a filterable list adapter used for auto completion.
getCompletionHint()This method returns optional hint text displayed at the bottom of the the matching list.
getDropDownAnchor()This method returns the id for the view that the auto-complete drop down list is anchored to.
getListSelection()This method returns the position of the dropdown view selection, if there is one.
isPopupShowing()This method indicates whether the popup menu is showing.
setText(CharSequence text, boolean filter)This method sets text except that it can disable filtering.
showDropDown()This method displays the drop down on screen.

Android MultiAutoCompleteTextView is an editable text view, extending AutoCompleteTextView, that can show completion suggestions for the substring of the text where the user is typing instead of necessarily for the entire thing.

You must must provide a MultiAutoCompleteTextView. Tokenizer to distinguish the various substring like comma (,).

Example

In this example I will show you how to implement AutoComplete and MultiAutoComplete TextView Android.

VIDEO DEMO

Let’s get start by creating a project in Eclipse IDE.

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details. (I kept my main activity name as MainActivity.java).

2.  Create a layout file for MainActivtiy.java under res ⇒ layout folder. I named the layout file as activity_main.xml. In this layout i had taken one AutoCompleteTextView and one MultiAutoCompleteTextView.

3. Now, go to values directory inside of res directory in that open the strings.xml file and add the following string array for setting items for AutoComplete suggestion keywords.

4. Now, come to MainActivity.java and add the following code. In this class we just get the string array from strings.xml and add to arraylist and set adapter to autocomplete textview. We have to set the threshold for both textview means to show hints after number of characters entered.

5. Now, run the app and you will get the output as shown in video.

Thanks. :)

 

Post comment

Your email address will not be published. Required fields are marked *