我对xamarin比较新。我正在使用自定义适配器listview。关于这个bug,我一直在脑子里徘徊。我正在尝试在listview中显示不同的更新列表。点击第一项(3项中的任何一项)工作正常..但我的问题是在点击第二项(可能是ShowAllLuzon或ShowAllMindanao)之后。它似乎没有刷新/更新我的列表视图,我的列表视图中的项目消失了。我在java中看到了InvalidateViews并尝试了InvalidateOptionMenu();但它似乎没有正常工作..或者我使用它错了?我应该在我的Update方法customadapter中添加它吗?
我在代码栏中的代码
else if (id == Resource.Id.ShowAllLuzon) //show LUZON
{
List<Mountain> filteredMountains = (from mountain in mMountains
where mountain.Island == 1
orderby mountain.MtName
select mountain).ToList();
mAdapter.Update(filteredMountains);
RunOnUiThread(() => mAdapter.NotifyDataSetChanged());
}
else if (id == Resource.Id.ShowAllVisayas) //show Visayas
{
List<Mountain> filteredMountains = (from mountain in mMountains
where mountain.Island == 2
orderby mountain.MtName
select mountain).ToList();
mAdapter.Update(filteredMountains);
RunOnUiThread(() => mAdapter.NotifyDataSetChanged());
}
else if (id == Resource.Id.ShowAllMindanao) //show Mindanao
{
List<Mountain> filteredMountains = (from mountain in mMountains
where mountain.Island == 3
orderby mountain.MtName
select mountain).ToList();
mAdapter.Update(filteredMountains);
InvalidateOptionsMenu(); //where I added InvalidateOptionsMenu
RunOnUiThread(() => mAdapter.NotifyDataSetChanged());
}
我也尝试在CustomAdapter中重新安排我的Update方法..
这是我的CustomAdapter中的Update方法..
public void Update(List<Mountain> mLists)
{
mtList.Clear();
mtList.AddRange(mLists);
NotifyDataSetChanged();
}
已经在这工作了近3个小时..请任何答案都非常感谢..