我有一个奇怪的/独特的情况与我的ListView
。这是场景:异步调用后ListView不更新
我正在使用MVP设计模式。当Activity
启动时,它会引发一个事件通知演示者从Web服务中获取一些数据。 Web服务调用是一个异步调用。一旦Web服务Completed
事件发生,我将结果推送到属于我的View
/Activity
中的属性(Array的类型)。
我提到的一切都很好,但只要设备旋转,一些有趣的发展发生。
异步调用恢复正常,并为属性(数组)提供值。所以没有错......(是的,有收集数据)然后我设置ListView Adapter
并打电话notifyDataSetChanged
,但没有任何反应。用户界面没有更新或什么?如果我重新输入Activity
,数据会再次显示?
我甚至试图在ListView
上打电话invalidateViews
和invalidate
- 这没有做任何事情。
请问有人能帮我解决这个问题吗? 非常感谢提前!
[更新]
我想强调的是,我正在使用C#(Xamarin),而不是Java的事实(:感叹: - 是的,我知道)。此外,我没有使用ASyncTask
类,而是使用由Visual Studio生成的代理类中创建的异步方法。非常简单的,但是这是填充ListView
编码 - 属性是从主持人设置
演示
哪里查看类型为IContactsView
protected override void OnCollectData(System.Collections.IEnumerable data, Type typeOfData)
{
if (data != null && typeOfData != null && typeOfData.Equals(typeof(UserContact)))
{
this.View.UserInformationCollection = data.Cast<UserContact>().ToArray();
}
}
活动
活动实施TS IContactsView
public UserContact[] UserInformationCollection
{
get
{
return this._userInformationCollection;
}
set
{
this.RunOnUiThread(() =>
{
this._userInformationCollection = value;
ListView listview = this.FindViewById<ListView>(Resource.Id.userLV);
if (listview != null)
{
UserContact[] subsidiesList = this.GetIndexedContacts(this._userInformationCollection);
listview.Adapter = new ContactsAdapter(this, subsidiesList.ToList());
((ContactsAdapter)listview.Adapter).NotifyDataSetChanged();
}
});
}
}
[/更新]