Android - Simple Auto Complete List

Submitted by: 
Operating System: 
Visitors have accessed this post 1055 times.

In this tutorial we will try to create a Simple Auto Complete using Android. This simple app predict the word that you will type and give you some list about the word that you want. Android is basically a piece of software which allows your hardware to function. It used in several gadget like smartphone, tablet, and even television. The android is an open source operating system it's free and user friendly to mobile developers. So let's now do the coding...

Getting Started:

First you will have to download & install the Android Development IDE (Android Studio or Eclipse). Android Studio is an open source development feel free to develop your things.

Here's the link for the Android Studio

Layout Design

We will now create the design for the application, first locate the layout file called activity_main.xml, this is the default name when create a new activity. Then write these codes inside your layout file.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="<a href=""
  3. " rel="nofollow">"
  4. </a> xmlns:app="<a href=""
  5. " rel="nofollow">"
  6. </a> xmlns:tools="<a href=""
  7. " rel="nofollow">"
  8. </a> android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. tools:context="com.razormist.simpleautocompletelist.MainActivity">
  13. <AutoCompleteTextView
  14. android:id="@+id/act_list"
  15. android:layout_alignParentStart="true"
  16. android:layout_alignParentLeft="true"
  17. android:layout_width="wrap_content"
  18. android:ems="14"
  19. android:layout_alignParentTop="true"
  20. android:layout_marginTop="80dp"
  21. android:layout_height="wrap_content"
  22. android:hint="Enter Here"/>
  24. android:id="@+id/btn_search"
  25. android:layout_width="wrap_content"
  26. android:layout_height="wrap_content"
  27. android:layout_marginTop="80dp"
  28. android:layout_alignParentEnd="true"
  29. android:layout_alignParentRight="true"
  30. android:layout_toRightOf="@+id/act_list"
  31. android:text="Search"/>
  35. </RelativeLayout>

Android Manifest File

The Android Manifest file provides essential information about your app to the Android system in which the system must required before running the code. It describe the overall information about the application. It contains some libraries that needed to access the several method within the app.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="<a href=""
  3. " rel="nofollow">"
  4. </a> package="com.razormist.simpleautocompletelist">
  6. <application
  7. android:allowBackup="true"
  8. android:icon="@mipmap/ic_launcher"
  9. android:label="@string/app_name"
  10. android:roundIcon="@mipmap/ic_launcher_round"
  11. android:supportsRtl="true"
  12. android:theme="@style/AppTheme">
  13. <activity android:name=".MainActivity"
  14. android:configChanges="orientation"
  15. android:screenOrientation="portrait">
  16. <intent-filter>
  17. <action android:name="android.intent.action.MAIN" />
  19. <category android:name="android.intent.category.LAUNCHER" />
  20. </intent-filter>
  21. </activity>
  22. </application>
  23. </manifest>

The Main Function

This code contains the main function of the application. This code will display a list that predict the letter that you enter. To start with first locate your MainActivity java file and open it, then write these some important variables inside the MainActivity class.

  1. private AutoCompleteTextView autoCompleteTextView;
  2. private Button btn_search;
  4. String[] languages = {"C", "C++", "C#", "PHP", "Python", "Java", "BASIC", "Pascal", "Perl", "Ruby", "VB", "Scala"};

Then after that write these block of codes inside onCreate method, this code will start the app when run.

  1. btn_search = (Button)findViewById(;
  2. autoCompleteTextView = (AutoCompleteTextView)findViewById(;
  4. ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.select_dialog_item, languages);
  5. adapter.sort(new Comparator<String>() {
  6. @Override
  7. public int compare(String lhs, String rhs) {
  8. return lhs.compareTo(rhs);
  9. }
  10. });
  11. autoCompleteTextView.setThreshold(1);
  12. autoCompleteTextView.setAdapter(adapter);
  14. btn_search.setOnClickListener(new View.OnClickListener() {
  15. @Override
  16. public void onClick(View v) {
  17. if(!autoCompleteTextView.getText().toString().equals("")){
  18. String text = autoCompleteTextView.getText().toString();
  19. Toast.makeText(MainActivity.this, text, Toast.LENGTH_SHORT).show();
  20. }
  21. }
  22. });

Try to run the app and see if it worked.

There you have it we create a Simple Auto Complete List using Android. I hope that this tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.