How to Create AutoCompleteTextView Suggestions in Android

In this tutorial, we are going to learn how to create AutoCompleteTextView Suggestions in android application. AutoCompleteTextView is similar to android Editview but with the extra feature of text suggestions why typing in AutoCompleteTextView.

Text suggestion is an important feature in many android application and it also help app users to compete the text they intend to type after entering few characters.

According to Google’s developers guide – AutoCompleteTextView is 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.

Text suggestion can also be used in a ListView. You can read my post on Android ListView with Search Box or Android ListView with EditText Filter

Before we start soiling our hands with code, it is important for us to learn about the different attributes associated with AutoCompleteTextView

[table id=7 /]

Before we start, the first thing I will do is to list the environment and tools I used in this android code snippet but feel free to use whatever environment or tools you are familiar with.

Windows 7

Android Studio

Samsung Galaxy Fame Lite

Min SDK 14

Target SDK 19

To create a new android application project, following the steps as stipulated below.

Go to File menu

Click on New menu

Click on Android Application

Enter Project name: AutoCompleteTextViewSuggestions

Package: com.inducesmile.autocompletetextviewsuggestions

Keep other default selections.

Continue to click on next button until Finish button is active, then click on Finish Button

Once you are done with creating your project, make sure you change the package name if you did not use the same package.

What we will do in our activity_main.xml file

1. In our activity_main.xml file, we will add an AutoCompleteTextView

The code for the xml file is shown below

<RelativeLayout xmlns:android=""
















android:layout_centerHorizontal="true" />


What we will do in our file

1. We get the instance of the AutoCompleteTextView by using findViewById method of the activity class.

2. We created a String array and populate it with some data.

3. We create an instance of an ArrayAdapter and pass three parameters to its constructor.

4. We finally set the ArrayAdapter to our instance of AutoCompleteTextView.

Copy and paste this code sample to file as shown below


import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends ActionBarActivity {

private AutoCompleteTextView autoCompleteTextView;


protected void onCreate(Bundle savedInstanceState) {



autoCompleteTextView = (AutoCompleteTextView)findViewById(;

String[]dataStorage = {"Nigeria", "Ghana", "Mali", "South Africa", "Cameroon", "Niger", "Algeria", "Zimbabwe"};

ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.select_dialog_item, dataStorage);





public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(, menu);

return true;



public boolean onOptionsItemSelected(MenuItem item) {

// Handle action bar item clicks here. The action bar will

// automatically handle clicks on the Home/Up button, so long

// as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();

//noinspection SimplifiableIfStatement

if (id == {

return true;


return super.onOptionsItemSelected(item);


Save the file and run your project. If everything works for you, an image like this will appear on your test device.

auto complete TextView

You can download the code for this tutorial below. If you are having hard time downloading the tutorials, kindly contact me.

Remember to subscribe with your email so that you will be among the first to receive our new post once it is published


  1. Avatar

Add a Comment