Android Autocomplete Textview Example

What is 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.

Layout architecture:

The application that we are going to develop has a simple screen with TextView.


Quick Links

Project Structure

Create layout XML

  • Create new android project [File >> New >> Android Project] with project name AutoCompleteTextView
  • Click next and select target android device version [I chose version 2.2]
  • Click next and enter package name – ‘’
  • Click finish

Code Listings

Open main.xml, now you can view the layout as either XML or in graphical view and just replace the XML with below one:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""


  1. Create Array adapter – Define drop down style and string array
  2. Retrieve the AutoCompletTextView widget in UI that we need to interact with programmatically
  3. Set threshold – Number of characters the user must type before the drop down list is shown

  4. Set the array adapter to the AutoCompleteTextView widget object

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends Activity {

	String[] languages = { "C","C++","Java","C#","PHP","JavaScript","jQuery","AJAX","JSON" };

	/** Called when the activity is first created. */
	public void onCreate(Bundle savedInstanceState) {
                //Create Array Adapter
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.select_dialog_singlechoice, languages);
                //Find TextView control
		AutoCompleteTextView acTextView = (AutoCompleteTextView) findViewById(;
		//Set the number of characters the user must type before the drop down list is shown
                //Set the adapter



Let us test the application:
Run click on the project >> Run as >> Android application
You could see following screen:

Download Source Code

Entire project is zipped and is available for download. Unzip the downloaded project and to import the project into eclipse, launch eclipse >> File >> Import.. >> Choose downloaded project(How to import android project in eclipse). If you just want to run the application in your mobile and see the output but don’t want to hit your head with source code, download application(apk) file and install it in your mobile device.

Download Source Code Download Application(apk)

*apk in Android is the installation file simliar to exe in windows.


I hope you enjoyed the post!! 🙂
Keep posted with your valuable comments below 🙂


Android AutoComplete TextView


Related Articles

Author: Udhay

Share This Post On
468 ad
Join now to get more access to our Android Tutorials

Join now to get more access to our Android Tutorials

Once you Join, you will receive Mail containing latest Android Tutorials once a month !!

I promise I wont spam you !!

You have Successfully Subscribed!

Pin It on Pinterest