我有一个Android小工具,使用
RemoteViewsFactory
以便填充ListView。
我的数据源是一个异步JSON调用,可以在任何时候完成(它不是推送通知)。现在代码位于
onDataChanged
看起来像这样:
@Override
public void onDataSetChanged() {
// Subsequent calls to get the data.
// Called when the widget onReceive ACTION_APPWIDGET_UPDATE procs.
newsGetter.updateListFeed(null, new NewsGetter.OnUpdateListFeedFinishedListener() {
@Override
public void onUpdateListFeedFinished(VolleyError error) {
//called when async call has finished. not sure what to call here?
}
});
Log.e(TAG, "******************************** onDataSetChanged PROVIDER");
}
每小时(我已设定
updatePeriodMillis
每小时更新一次)我的
AppWidgetProvider
得到一个
onReceive
打电话要求更新(
ACTION_APPWIDGET_UPDATE
)因此,我上面的代码运行。但是,在我的代码运行和更新之后
feedItems
,即使在滚动时,UI也不会更新。
所以我的问题是:如何使UI失效并让它重新绘制所有视图?
到目前为止,我尝试过:
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widget_list);
但这也需要
onDataChanged(数据已更改)
这将导致无限循环,所以我不能使用它。