从远程填充 AutoCompleteTextView API

Populate AutoCompleteTextView from a remote API

我的 Xamarin 应用程序上有一个过滤器对话框,它将有一个自动完成文本视图,为用户提供一种可搜索的方式来查找项目。

问题是自动完成数据将来自 API,我很难找到有效的解决方案。

我正在学习 this 教程,但在让过滤正常工作方面有点迷茫。

您只想将来自(web api) 的数据设置到您的 AutoCompleteTextview 的适配器中

一个简单的例子:

activity中:

[Activity(Label = "AutoComplextActivity", MainLauncher = true)]
public class AutoComplextActivity : Activity
{
    private ArrayAdapter<string> adapter;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Create your application here
        SetContentView(Resource.Layout.autocomplext_layout);
        AutoCompleteTextView acTextView = (AutoCompleteTextView)FindViewById(Resource.Id.id_autotextView);
        adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleDropDownItem1Line);
        acTextView.Adapter=adapter;
        GetData();                 
    }

    private void GetData()
    {
        //get data form web api,for example the data is below
        List<string> data = new List<string>();
        data.Add("beijing1");
        data.Add("beijing2");
        data.Add("beijing3");
        data.Add("shanghai1");
        data.Add("shanghai2");
        data.Add("guangzhou1");
        data.Add("shenzhen");
        data.Add("adadadsgua");

        //add data into adapter
        adapter.AddAll(data);
        adapter.NotifyDataSetChanged();
    }
}