Browse By

Android: AutoCompleteTextView Example in Android Studio 2.0

In previously article, we have seen EditText Example. In this tutorial, we will migrate  AutoCompleteTextView example to Android Studio 2.0 from Eclipse. 😀

Android: AutoCompleteTextView Example in Android Studio 2.0Android AutoCompleteTextView is the subclass of EditText class. It shows a list of completion suggestions automatically while the user is typing. The list of suggestions is displayed in the drop-down menu.

Following are the important attributes related to AutoCompleteTextView control.

  1. android:completionHint
    This defines the hint displayed in the drop down menu.
  2. android:completionHintView
    This defines the hint view displayed in the drop down menu.
  3. android:completionThreshold
    This property will define the number of characters that the user must type before completion suggestions are displayed in a drop-down menu.
  4. android:dropDownAnchor
    This is the View to anchor the auto-complete dropdown to.
  5.  android:popupBackground
    This sets the background.

Direct Download Full Source Code

Android: AutoCompleteTextView Example in Android Studio 2.0

Let’s create an Android Application which shows the use of AutoCompleteTextView. It is a Simple application which allows you to select your country.
Create a new project and fill the required details:
File -> New -> New Project

  1. After Creating Project, open res –> layout
  2. Open content_main.xml and add AutoCompleteTextView control in it as follows:
 android:hint="Select Country" />

 One of the most important property of AutoCompleteTextView control is “completionThreshold”

3. Now open your

  • Initialize the AutoCompleteTextView control in it.
  •  Create an array adapter for storing list array.
public class MainActivity extends AppCompatActivity {

 //ui controls
 AutoCompleteTextView autoCompleteTextView;

 //class members
 String countries[] = { "INDIA", "ITALY", "JAPAN", "USA", "ICELAND",
 ArrayAdapter<String> adapter;

 protected void onCreate(Bundle savedInstanceState) {
 Toolbar toolbar = (Toolbar) findViewById(;

 autoCompleteTextView = (AutoCompleteTextView) findViewById(;
 adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, countries);



4. Handle the AutocompleteTextView click event using setOnItemClickListener() method. Place below lines of code in onCreate() method.

autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
   String s = parent.getItemAtPosition(position).toString(); 
   Toast toast= Toast.makeText(getApplicationContext(), s + " is clicked", Toast.LENGTH_SHORT);

5. Now Execute Application

Android: AutoCompleteTextView Example in Android Studio 2.0


I hope you like this article. Share your views to improve content. Please stay tune with us. In next article, we will learn Android Spinner (DropDown List) Example in Android Studio 2.0. Happy coding!!

Subscribe for more articles!!

Download Full Source Code