【发布时间】:2021-04-14 07:02:09
【问题描述】:
我创建了一个适配器:
// public
ArrayAdapter<string> adapter { get; set; }
List<string> autocomplete = new List<string>();
// OnCreate()
AutoCompleteTextView autoComplete = FindViewById<AutoCompleteTextView>(Resource.Id.autoCompleteTextView1);
adapter = new ArrayAdapter<string>(this, Resource.Layout.list_item, autocomplete);
autoComplete.Adapter = adapter;
autoComplete.Threshold = 5;
这里我想换个适配器或者添加建议
// AfterTextChanged()
adapter.Clear(); // Clear Adapter (previous suggestions)
// Get Autocomplete from Locationiq und Deserialize it
List<AutoComplete> auto = await GetAutoComplete(FindViewById<AutoCompleteTextView>(Resource.Id.autoCompleteTextView1).Text, Encoding.UTF8.GetString(Convert.FromBase64String(locationiq)));
List<string> temp = new List<string>();
foreach (AutoComplete city in auto)
{
temp.Add(city.display_place); // Show only the display place (not coordinates etc)
}
autocomplete = temp; // Change the List
adapter.NotifyDataSetChanged(); // Notify that data changed
如果我在使用静态数据的适配器之前创建列表,它可以正常工作,但我无法让它与动态数据一起使用
有人可以帮我解决这个问题吗?我查了很多东西,但我能找到一个可行的解决方案
【问题讨论】:
标签: c# xamarin xamarin.android android-adapter autocompletetextview