如何在Xamarin表单中使用AutoCompleteTextView

时间:2019-05-07 14:10:06

标签: xamarin xamarin.forms

我正在尝试以xamarin形式实现AutocompleteTextview, 到现在为止,我已经实现了自定义功能,并查看了我的自动完成栏所需的外观, 但是我卡住的是从共享库向Dataadapter填充数据,但我也没有在入口栏中选择什么文本,所以有人可以帮助我如何将我的列表从pcl绑定到本机,并且我还需要两个数据到文本属性的方式

这是我到目前为止已经实现的代码

我的普通班

public class AutoCompleteViewv3 : View
{
    public AutoCompleteViewv3()
    {

    }  

}

我的Android实现

[assembly: ExportRenderer(typeof(AutoSuggestBox), 
typeof(AutoCompleteViewRendererv3))]
  namespace PredictiveList.Droid
   {
   public class AutoCompleteViewRendererv3  : 
                      ViewRenderer<AutoCompleteViewv3, 
          AutoCompleteTextView>
{
    static string[] COUNTRIES = new string[] {
   "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
    "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", };

    public AutoCompleteViewRendererv3(Android.Content.Context context) : base(context)
    {

    }

    protected override void OnElementChanged(ElementChangedEventArgs<AutoCompleteViewv3> e)
    {
        base.OnElementChanged(e);

        if (e.OldElement != null || this.Element == null)
            return;


        AutoCompleteTextView textView = (AutoCompleteTextView)LayoutInflater.From(Context).Inflate(Resource.Layout.TextEditorLayouts, null);

        var adapter = new ArrayAdapter<String>(Context, 
    Resource.Layout.list_item, COUNTRIES);
        textView.Adapter = adapter;
        SetNativeControl(textView);
    }

    // Use the control here.
    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);

        if (this.Element == null || this.Control == null)
            return;

        // variable this.Control is the AutoCompleteTextView, so you an manipulate it.
    }
}

}

对于Ios,我仍在尝试实现

1 个答案:

答案 0 :(得分:0)