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. <TextView
  8. android:id="@+id/textView1"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:layout_alignParentLeft="true"
  12. android:layout_alignParentTop="true"
  13. android:layout_marginTop="15dp"
  14. android:text="what is your favourite programming language" />
  15. <AutoCompleteTextView
  16. android:id="@+id/autoCompleteTextView1"
  17. android:layout_width="wrap_content"
  18. android:layout_height="wrap_content"
  19. android:layout_marginLeft="36dp"
  20. android:layout_marginTop="19dp"
  21. android:ems="10"
  22. android:text=""
  23. android:layout_below="@+id/textView1"
  24. android:layout_alignEnd="@+id/textView1"
  25. android:layout_marginEnd="19dp">
  26. <requestFocus />
  27. </AutoCompleteTextView>
  28. </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. import android.os.Bundle;
  3. import android.app.Activity;
  4. import android.graphics.Color;
  5. import android.view.Menu;
  6. import android.widget.ArrayAdapter;
  7. import android.widget.AutoCompleteTextView;
  8. public class MainActivity extends Activity {
  9. String[] language ={"C","C++","Java",".NET","iPhone","Android","ASP.NET","PHP"};
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_main);
  14. ArrayAdapter<String> adapter = new ArrayAdapter<String>
  15. (this,android.R.layout.select_dialog_item,language);
  16. AutoCompleteTextView actv= (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
  17. actv.setThreshold(1);
  18. actv.setAdapter(adapter);
  19. actv.setTextColor(Color.BLUE);
  20. }
  21. @Override
  22. public boolean onCreateOptionsMenu(Menu menu) {
  23. getMenuInflater().inflate(R.menu.activity_main, menu);
  24. return true;
  25. }
  26. }
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