Skip to content

Instantly share code, notes, and snippets.

@bigkiandi
Created May 13, 2017 13:22

Revisions

  1. bigkiandi created this gist May 13, 2017.
    46 changes: 46 additions & 0 deletions MainActivity.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    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 MainActivity : Activity
    {
    AutoCompleteTextView autocomplete1;
    Button btn_Submit;


    protected override void OnCreate(Bundle bundle)
    {
    base.OnCreate(bundle);

    // Set our view from the "main" layout resource
    SetContentView(Resource.Layout.Main);
    autocomplete1 = FindViewById<AutoCompleteTextView>(Resource.Id.autoComplete1);
    btn_Submit = FindViewById<Button>(Resource.Id.btn_Submit);
    var kota = new string[] { "Makassar", "Balikpapan", "Jakarta", "Jogja", "Surabaya", "Ambon", "Medan" };
    ArrayAdapter adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerItem, kota);
    autocomplete1.Adapter = adapter;

    btn_Submit.Click += Btn_Submit_Click;

    }

    private void Btn_Submit_Click(object sender, EventArgs e)
    {
    if (autocomplete1.Text!="")
    {
    Toast.MakeText(this, "Kota dimasukkan =" + autocomplete1.Text, ToastLength.Short).Show();
    }
    else
    {
    Toast.MakeText(this, "silahkan masukan nama kota dulu", ToastLength.Short).Show();
    }
    }
    }
    }