【问题标题】:Searchable Dropdown spinner xamarin AndroidSearchable Dropdown spinner xamarin Android
【发布时间】:2017-03-05 13:46:21
【问题描述】:

可搜索的下拉式微调器 嗨,我有完整的 sqlite 数据库微调器,我想要可以在其中搜索 我怎样才能做到这一点 我尝试使用自动完成文本但效果不佳 这是我的 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" />

这是我的活动

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

【问题讨论】:

    标签: java c# android xamarin xamarin.android


    【解决方案1】:

    我认为您必须将 Spinner 与 AutoCompleteTextView 结合使用,例如Combine Spinner and AutoCompleteTextView

    【讨论】:

    • System.NullReferenceException: 对象引用未设置为对象的实例。使用时会出现此错误actv = FindViewById(Resource.Id.autoCompleteTextView1); actv.Adapter = 适配器;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多