|
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.axml 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 i.e.
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();
}
}
}
}
|