Esraa
Esraa

Reputation: 33

Searchable Dropdown spinner xamarin Android

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();
} 

Upvotes: 1

Views: 1850

Answers (1)

Alessandro Caliaro
Alessandro Caliaro

Reputation: 5768

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

Upvotes: 0

Related Questions