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>
你可以通过调用AppWidgetManager notifyAppWidgetViewDataChanged (int appWidgetId, int viewId) 方法来请求更新.
调用了该方法之后,系统会对RemoteViewsFactory的onDataSetChanged()方法进行回调, 在这里你可以进行最新数据的提取.
注意 :你可以在 onDataSetChanged()回调函数中做一些耗时工作(同步的)的处理。系统将保证这些操作在从RemoteViewsFactory返回新数据的信息或View之前完成。
另外, 你可以在getViewAt()返回中进行耗时操作的处理. 如果getViewAt()超过一定的时限,系统就先用RemoteViewsFactory的getLoadingView()返回的View进行显示,直到getViewAt()完成。
评论这张
转发至微博
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值