- Start a new project named AutoComplete

- Go to the Resources\layout\main.xml file and make changes
<?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="wrap_content"
>
<AutoCompleteTextView android:id="@+id/ACT"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
In the above code you can see I create an simple AutoCompleteTextView.
-
Add a new Android layout inside the project layout folder


-
Open layout1.axml file and make changes, here we create a simple TextView for the items
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="15sp"
android:textColor="#000"
></TextView>
-
Set the Build Action of layout1.axml file to AndroidResource
-
Now go to the Activity1.cs and create an string array inside the Activity1 class named names and insert values for it
static string[] names = new string[] {"Hello" , "He" , "Hell" , "Hewells" , "Heat" , "Henrry" , "House" , "Hole"};
-
At last write the following code below inside the OnCreate() method
AutoCompleteTextView textView = FindViewById<AutoCompleteTextView>(Resource.Id.ACT);
var adapter = new ArrayAdapter<String>(this, Resource.Layout.layout1, names);
textView.Adapter = adapter;
Here is the complete code of Activity.cs
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace AutoComplete
{
[Activity(Label = "AutoComplete", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
static string[] names = new string[] { "Hello", "He", "Hell", "Hewells", "Heat", "Henrry", "House", "Hole" };
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
AutoCompleteTextView textView = FindViewById<AutoCompleteTextView>(Resource.Id.ACT);
var adapter = new ArrayAdapter<String>(this, Resource.Layout.layout1, names);
textView.Adapter = adapter;
}
}
}
-
Run the application, output looks like below

As you see above AutoComplete will populate the list of suggestions like you enter he than all the matching records will come out in the list. And following you see that if you increase the text like he to hel only two matching records will shows.
