Android autocompletetextview Example Tutorial

Autocompletetextview tag is used to show multiple type of user selected selections through a MySQL database or a string file. Autocompletetextview basically show the user type words related choice on drop down format. There are lot’s of examples available for use of autocompletetextview like when we trying to find contacts on our android mobile phone then it will show them in drop down format or the best example if Google itself. Each and every time after typing your query on Google search engine box it will show you the related keywords match and you can select them by clicking or tapping. So here is the compete step by step tutorial for Android autocompletetextview Example Tutorial .

android-project-download-code-button

Android autocompletetextview Example Tutorial.

Code for Add autocompletetextview in android activity layout activity_main.xml file.

 <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"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.autocompletetextview.MainActivity" >

 <AutoCompleteTextView
 android:id="@+id/autoCompleteTextView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="86dp"
 android:ems="10"
 android:text="Type your text here" >

 <requestFocus />
 </AutoCompleteTextView>

</RelativeLayout>

Code for MainActivity.java programming file.

 package com.android_examples.com.autocompletetextview;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends Activity {

 AutoCompleteTextView TypeText;
 String[] TextStringValue = { "Android-Examples.com","Android Tutorials","Android code examples","android programming codes" };
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 TypeText = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
 ArrayAdapter<String> TopicName = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, TextStringValue);
 TypeText.setAdapter(TopicName);
 TypeText.setThreshold(3);

 
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
 // Inflate the menu; this adds items to the action bar if it is present.
 getMenuInflater().inflate(R.menu.main, menu);
 return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
 // Handle action bar item clicks here. The action bar will
 // automatically handle clicks on the Home/Up button, so long
 // as you specify a parent activity in AndroidManifest.xml.
 int id = item.getItemId();
 if (id == R.id.action_settings) {
 return true;
 }
 return super.onOptionsItemSelected(item);
 }
}

Screenshots :

Android autocompletetextview Example Tutorial

Click Here To Download Android autocompletetextview Example Tutorial Project.