Introduction
In this article, I will show you how to create an Auto-Complete Text View Android App using Android Studio.
Requirements
- Android Studio version 2.3.3
- Little bit XML and JAVA knowledge.
- Android Emulator (or) Android mobile
- Download link (Android Studio)
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.

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.

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.

Step 4
Now, add the activity and click the "Next" button.

Step 5
Add Activity name and click "Finish".

Step 6
Go to activity_main.xml. This XML file contains the designing code for your Android app.

The XML code is given below:
- <RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity" >
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:layout_marginTop="15dp"
- android:text="what is your favourite programming language" />
- <AutoCompleteTextView
- android:id="@+id/autoCompleteTextView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="36dp"
- android:layout_marginTop="19dp"
- android:ems="10"
- android:text=""
- android:layout_below="@+id/textView1"
- android:layout_alignEnd="@+id/textView1"
- android:layout_marginEnd="19dp">
- <requestFocus />
- </AutoCompleteTextView>
- </RelativeLayout>
Step 7
Go to Main Activity.java. This Java program is the backend language for Android.
The java code is given below.

- package abu.autocompletetextview;
- import android.os.Bundle;
- import android.app.Activity;
- import android.graphics.Color;
- import android.view.Menu;
- import android.widget.ArrayAdapter;
- import android.widget.AutoCompleteTextView;
- public class MainActivity extends Activity {
- String[] language ={"C","C++","Java",".NET","iPhone","Android","ASP.NET","PHP"};
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ArrayAdapter<String> adapter = new ArrayAdapter<String>
- (this,android.R.layout.select_dialog_item,language);
- AutoCompleteTextView actv= (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
- actv.setThreshold(1);
- actv.setAdapter(adapter);
- actv.setTextColor(Color.BLUE);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.activity_main, menu);
- return true;
- }
- }
Step 8
Now, go to the menu bar and click "Make Project" or press ctrl+f9 to debug the error.
Step 9

Then, click the "Run" button or press shift+f10 to run the project. And choose the "virtual machine" option and click OK.

Conclusion
We have successfully built the Autocomplete Text View Android application.



Join the conversation! Your thoughts help the community grow.