android AutoCompleteTextView ExampleAutoCompleteTextView in Android :

When you type in an editable (text field), you get some suggestions automatically in dropdown, you can do that via AutoCompleteTextView widget in Android.

While you can use an EditText view for entering text, it’s generally helpful to provide users with suggestions to automatically complete what they’re typing. as an example, if a user is typing a search string into an EditText, you can provide possible suggestions to complete the search string while the user is typing. in this case, you’ll be able to use the AutoCompleteTextView to do so. This example shows you the way.

Note : This example (Project) is developed in Eclipse Version Kepler,tested on Android 4.4.2 (KitKat Version) and SDK build-tools 22.6.3

Solution Stuff :

In Android, use the AutoCompleteTextView, use the <AutoCompleteTextView> element and put it into your UI file and use “android.widget.AutoCompleteTextView” class to render a AutoCompleteTextView.

You just need to drag and drop  <AutoCompleteTextView> widget in Android UI (according below figure) and write some code for AutoCompleteTextView application in java class and xml file:

android AutoCompleteTextView

Complete Code :

1. Open “res/layout/activity_main.xml” file. To use the “AutoCompleteTextView ” element and put this xml code it into your activity_main.xml file:

Note: In the top image only show how to put autocomplete in UI, this code already have “AutoCompleteTextView ” UI element.

File : res/layout/activity_main.xml

The AutoCompleteTextView is an editable text view that shows completion suggestions while the user is typing. The suggestions drop-down menu displayed as a computer menu that contains content that’s provided by you.

2. Open “MainAcitvity.class” file and add following JAVA code.

File : src/package-name/

You first created an array containing a list of presidents’ names. You then created an ArrayAdapter object, specifying you want you would like to show the list of names, as well as the array containing the names.
You set the AutoCompleteTextView’s threshold to [2] so that the suggestions can appear only when the user has written a minimum of 2 characters. You then need to set the AutoCompleteTextView to use the array adapter you have simply created.

Figure shows AutoCompleteTextView Output in Android emulator :

android AutoCompleteTextView

Download Android AutoCompleteTextView example Source code :

Leave a Reply