Introduction
AutoCompleteTextView is an Editable TextView for displaying suggestions when the user starts typing in the control. The Suggestions are displayed in a drop down menu and when the user selects the item from the drop-down list, the selected text is displayed in a TextView. Before starting, I suggest you read my previous articles in this series.
Let's Start.
Method 1
Using Default Android Resources.
1. Create a New Android Application.


2. Drop a TextView, AutoCompleteTextView (with id="@+id/autoComplete1") and a Button control (with id="@+id/btn_Submit" and text="Submit") onto the Layout, Main.xaml.

The following is the Main.xaml source code:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TextView
- android:text="Enter Name"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:id="@+id/textView1"
- android:padding="5dp" />
- <AutoCompleteTextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:id="@+id/autoComplete1" />
- <Button
- android:text="Submit"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:id="@+id/btn_Submit" />
- </LinearLayout>
In Activity1.cs, create a String Array (named names) for displaying the AutoComplete Suggestion and an ArrayAdapter for filling in the View, AutoCompleteTextView, with the list of names (Array). We have also created a btn_Submit.Click event. On clicking the btn_Submit it will display the text present in autoComplete1 (AutoCompleteTextView) in a Toast message and if AutoCompleteTextView is empty then Display a Toast Message (in other words Please Enter Name!).
The following is the activity1.cs code:
- using Android.App;
- using Android. Widget;
- using Android.OS;
- namespace AutoCompleteTextViewExample
- {
- [Activity(Label = "AutoCompleteTextViewExample", MainLauncher = true, Icon = "@drawable/icon")]
- public class Activity1 : Activity
- {
- //Creating Instance of AutoCompleteTextView and Button
- AutoCompleteTextView autoComplete1;
- Button btn_Submit;
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- //setting the view for the Activity
- SetContentView(Resource.Layout.Main);
- //Get autoComplete1 AutoCompleteTextView and btn_Hello Button control from the Main.xaml Layout.
- autoComplete1 = FindViewById<AutoCompleteTextView>(Resource.Id.autoComplete1);
- btn_Submit = FindViewById<Button>(Resource.Id.btn_Submit);
- //string array used for displayling AutoComplete Suggestion
- var names = new string[] {"Anoop","Arjit","Akshay","Ankit","Rakesh"};
- //Use ArrayAdapter for filling the View in other words AutoCompleteTextView with the list of names(Array).
- //Use SimpleSpinnerItem(Predefined layout in Android Resources) for displaying the dropdown list
- ArrayAdapter adapter = new ArrayAdapter<string>(this,Android.Resource.Layout.SimpleSpinnerItem,names);
- autoComplete1.Adapter = adapter;
- btn_Submit.Click += btn_Submit_Click;
- }
- //btn_Submit Click Event
- void btn_Submit_Click(object sender, System.EventArgs e)
- {
- //Checking if autoComplete1.Text is not empty
- if (autoComplete1.Text != "")
- {
- Toast.MakeText(this, "Name Entered =" + autoComplete1.Text, ToastLength.Short).Show();
- }
- else
- {
- Toast.MakeText(this, "Please Enter Name!", ToastLength.Short).Show();
- }
- }
- }
- }

Method 2
Using Custom Resources.
In the preceding example, we used SimpleSpinnerItem for displaying the list in AutoCompleteTextView but we can also create Custom Resouces for displaying the Auto Suggested list. Let's add a new layout(named ListName.xaml) and drop a TextView Control onto it. Adjust textColor, textSize, padding and so on depending on your needs.
The following is the ListName.xaml code:
- <?xml version="1.0" encoding="utf-8"?>
- <TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:text="Text"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:id="@+id/textView1"
- android:padding="5dp"
- android:textSize="20dp"
- android:textColor="@android:color/black" />
- ArrayAdapter adapter = new ArrayAdapter<string>(this, Resource.Layout.ListName, names);

I hope you like this. Thanks.

Kshama MishraPosted Mar 11, 2015, 1:03 AM
can u please suggest me how can i search using google map data with auto complete textview
Saineshwar BageriPosted Dec 14, 2014, 11:27 PM
nice one sir