`
kanwoerzi
  • 浏览: 1645438 次
文章分类
社区版块
存档分类
最新评论

Widgets高级篇(四)

阅读更多
本文翻译整理自:<wbr style="line-height:22px"><span style="line-height:22px; font-family:Arial,Helvetica,simsun,u5b8bu4f53"><a rel="nofollow" href="http://developer.android.com/guide/topics/appwidgets/index.html#implementing_collections" style="color:rgb(207,121,28); line-height:22px; text-decoration:none">http://developer.android.com/guide/topics/appwidgets/index.html#implementing_collections</a></span></wbr>
3.7、数据更新
图2说明了App Widget with Collections如何进行数据更新。它也给我们展示了App Widget代码如何和RemoteViewsFactory进行交互, 和我们App Widget with Collections应该如何请求进行数据更新。
图2
Widgets高级篇(四) - hubingforever - 民主与科学
<wbr style="line-height:25px">App Widgets with collections的一个重要属性就是可以让用户进行手动更新数据.比如Android 3.0中的Gmail app widget, 提供邮件快照的inbox.为了显示最新的数据, 你需要让<a target="_blank" rel="nofollow" href="http://developer.android.com/reference/android/widget/RemoteViewsService.RemoteViewsFactory.html" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">RemoteViewsFactory</a>提取数据并更新collection view的显示.</wbr>
你可以通过调用AppWidgetManagernotifyAppWidgetViewDataChanged (int appWidgetId, int viewId)方法来请求更新.
调用了该方法之后,系统会对RemoteViewsFactory的onDataSetChanged()方法进行回调, 在这里你可以进行最新数据的提取.
注意:你可以在 onDataSetChanged()回调函数中做一些耗时工作(同步的)的处理。系统将保证这些操作在从RemoteViewsFactory返回新数据的信息或View之前完成。
另外, 你可以在getViewAt()返回中进行耗时操作的处理. 如果getViewAt()超过一定的时限,系统就先用RemoteViewsFactory的getLoadingView()返回的View进行显示,直到getViewAt()完成。
评论这张
转发至微博
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics