0

Searchable Dropdown spinner hi ,, I have spinner full by sqlite database I want can search in it how can i do that I try used Autocomplete text but not worked well this my spinner.aXml

 <Spinner
       android:layout_width="match_parent"
        android:layout_height="35dp"
        android:id="@+id/SpinnerHotel"
        android:paddingLeft="10dp"
        android:background="@drawable/Spinner_Style"
        android:spinnerMode="dropdown"
        android:gravity="center"
        android:visibility="visible"
        android:layout_marginRight="10dp"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="15dp" />


 and text_View.axml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="20dp"
                      android:id="@+id/autoCompleteTextView1" 
    android:textColor="#68767A"
    android:text="Select a Hotel .. "
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    android:textSize="18dp" />

and this my Activity

  async    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.GoShow_layout);

        Agent = FindViewById<Spinner>(Resource.Id.SpinnerAgentt);

        List<string> my_array = new List<string>();
          my_array = await login.Get_Hotel();
        ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Resource.Layout.Text_View, my_array);
        adapter.SetDropDownViewResource(Resource.Layout.Text_View);
        Hotel.Adapter = adapter;
        Hotel.ItemSelected += Hotel_ItemSelected;




    }

private void Agent_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
    var Spinner = sender as Spinner;
    string Agentt = Spinner.GetItemAtPosition(e.Position).ToString();

    Toast.MakeText(this, Agentt , ToastLength.Short).Show();
} 
Cœur
  • 37,241
  • 25
  • 195
  • 267
Esraa
  • 23
  • 7

1 Answers1

0

I think you have to combine Spinner with AutoCompleteTextView, like here Combine Spinner and AutoCompleteTextView

Community
  • 1
  • 1
Alessandro Caliaro
  • 5,623
  • 7
  • 27
  • 52
  • System.NullReferenceException: Object reference not set to an instance of an object.when used it get this erroractv = FindViewById(Resource.Id.autoCompleteTextView1); actv.Adapter = adapter; – Esraa Mar 05 '17 at 14:13
  • Take a look to this sample https://developer.xamarin.com/recipes/android/controls/autocomplete_text_view/add_an_autocomplete_text_input/ – Alessandro Caliaro Mar 05 '17 at 15:27