Auto-Complete Text View Android App Using Android Studio

Introduction

 
In this article, I will show you how to create an Auto-Complete Text View Android App using Android Studio.
 
Requirements
Steps to be followed
 
Follow these steps to create an Auto-complete Text View Android App. I have included the source code in the attachment.
 
Step 1
 
Open Android Studio and start a new Android Studio Project.
 
Text view Android App
 
Step 2
 
You can choose your application name and choose the location where your project is stored. If you wish to use C++ for coding the project, mark the "Include C++ support", and click the "Next" button.
 
Text view Android App
 
Step 3
 
Now, select the version of Android and select the target Android devices. We need to choose the SDK level which plays an important role in running the application.
 
Text view Android App
 
Step 4
 
Now, add the activity and click the "Next" button.
 
Text view Android App
 
Step 5
 
Add Activity name and click "Finish".
 
Text view Android App
 
Step 6
 
Go to activity_main.xml. This XML file contains the designing code for your Android app.
 
Text view Android App
 
The XML code is given below:
  1. <RelativeLayout  
  2.     xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     tools:context=".MainActivity" >  
  7.   
  8. <TextView  
  9.         android:id="@+id/textView1"  
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="wrap_content"  
  12.         android:layout_alignParentLeft="true"  
  13.         android:layout_alignParentTop="true"  
  14.         android:layout_marginTop="15dp"  
  15.         android:text="what is your favourite programming language" />  
  16.   
  17.     <AutoCompleteTextView  
  18.         android:id="@+id/autoCompleteTextView1"  
  19.         android:layout_width="wrap_content"  
  20.         android:layout_height="wrap_content"  
  21.         android:layout_marginLeft="36dp"  
  22.         android:layout_marginTop="19dp"  
  23.         android:ems="10"  
  24.         android:text=""  
  25.         android:layout_below="@+id/textView1"  
  26.         android:layout_alignEnd="@+id/textView1"  
  27.         android:layout_marginEnd="19dp">  
  28.         <requestFocus />  
  29.     </AutoCompleteTextView>  
  30. </RelativeLayout>  
Step 7
 
Go to Main Activity.java. This Java program is the backend language for Android.
 
Text view Android App
 
The java code is given below.
  1. package abu.autocompletetextview;  
  2.   
  3. import android.os.Bundle;  
  4. import android.app.Activity;  
  5. import android.graphics.Color;  
  6. import android.view.Menu;  
  7. import android.widget.ArrayAdapter;  
  8. import android.widget.AutoCompleteTextView;  
  9.   
  10. public class MainActivity extends Activity {  
  11.     String[] language ={"C","C++","Java",".NET","iPhone","Android","ASP.NET","PHP"};  
  12.     @Override  
  13.     protected void onCreate(Bundle savedInstanceState) {  
  14.         super.onCreate(savedInstanceState);  
  15.         setContentView(R.layout.activity_main);  
  16.   
  17.         ArrayAdapter<String> adapter = new ArrayAdapter<String>  
  18.                 (this,android.R.layout.select_dialog_item,language);  
  19.   
  20.         AutoCompleteTextView actv= (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);  
  21.         actv.setThreshold(1);   
  22.         actv.setAdapter(adapter);   
  23.         actv.setTextColor(Color.BLUE);  
  24.   
  25.     }  
  26.   
  27.     @Override  
  28.     public boolean onCreateOptionsMenu(Menu menu) {  
  29.           
  30.         getMenuInflater().inflate(R.menu.activity_main, menu);  
  31.         return true;  
  32.     }  
  33.   
  34. }  
Step 8
 
Now, go to the menu bar and click "Make Project" or press ctrl+f9 to debug the error.
 
Text view Android App
 
Step 9
 
Then, click the "Run" button or press shift+f10 to run the project. And choose the "virtual machine" option and click OK.
 
Text view Android App
 

Conclusion

 
We have successfully built the Autocomplete Text View Android application.
 
Text view Android App
 
Text view Android App