我的问题是这((BaseAdapter)listAdapter).NotifyDataSetChanged();
不起作用。我使用计时器每 X 分钟获取一次新闻。我进行了调试并看到了数据适配器的变化,但在屏幕上没有任何变化。如果我缩放屏幕上看到的新数据。加载时未触发列表视图单击事件。更改 listadapter 并执行缩放单击事件后。
请你帮助我好吗?
[Activity (Label = "SportNews")]
public class SportNews : Activity
{
RssFeedItemAdapter listAdapter;
JavaList<FeedItem> items = new JavaList<FeedItem>();
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView(Resource.Layout.list_view);
items = RssHelper.Instance.SportNews();
//ListAdapter = new ArrayAdapter<string> (this, Resource.Layout.list_item, items);
listAdapter = new RssFeedItemAdapter(this,items);
ListView listView = FindViewById<ListView>(Resource.Id.listView);
listView.Adapter = listAdapter;
((BaseAdapter)listAdapter).NotifyDataSetChanged();
listView.ItemClick += new EventHandler<AdapterView.ItemClickEventArgs>(listView_ItemClick);
Timer timer = new Timer(PushNews, null, TimeSpan.Zero, TimeSpan.FromMinutes(15)); // get time from user preferences...
}
private void PushNews(object state)
{
items = RssHelper.Instance.SportNews();
JavaList<FeedItem> feeds = new JavaList<FeedItem>();
feeds.Add(new FeedItem()
{
NewsPicture = "http://www.website.com/pic/test.jpg",
NewsTitle = "Test news",
NewsUrl = "http://www.google.com",
});
listAdapter = new RssFeedItemAdapter(this,feeds);
((BaseAdapter)this.listAdapter).NotifyDataSetChanged();
}
void listView_ItemClick(object sender, Android.Widget.AdapterView.ItemClickEventArgs e)
{
//Get our item from the list adapter
var item = this.listAdapter.GetItemAtPosition(e.Position);
var intent = new Intent();
intent.SetClass(this, typeof(NewsView));
intent.PutExtra("Url", item.NewsUrl);
StartActivity(intent);
}
}