2017-03-05 52 views
0

檢索下拉微調 您好,,我有微調全額SQLite數據庫我希望能在這 搜索我怎麼能做到這一點 我嘗試使用自動完成文本,但效果並不好 這個我spinner.aXml檢索下拉微調xamarin的Andriod

<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" /> 

,這我的活動

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

回答

0

我認爲你必須與微調結合AutoCompleteTextView,喜歡這裏Combine Spinner and AutoCompleteTextView

+0

System.NullReferenceException:對象引用未設置爲對象的實例。使用它時獲取此erroractv = FindViewById (Resource.Id.autoCompleteTextView1); actv.Adapter = adapter; – Esraa

+0

看看這個示例https://developer.xamarin.com/recipes/android/controls/autocomplete_text_view/add_an_autocomplete_text_input/ –

+0

謝謝我遵循示例,我做到了 – Esraa