刚刚更新完全地创建一个新的小窗口RemoteViews呢? [英] Just update a widget RemoteViews instead of completly creating a new one?

查看:173
本文介绍了刚刚更新完全地创建一个新的小窗口RemoteViews呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在我的AppWidgetProvider类的OnUpdate方法,我最终执行的code一个不平凡的量,这样我可以完全重新创建一个新的RemoteViews对象。现实的情况是我真的只需要在每一次我更新textviews在RemoteViews之一,被设置的文本。反正是有,只是一个特定的部件已经在使用修改RemoteViews?

So in my onUpdate method in my AppWidgetProvider class, I ended up executing a non-trivial amount of code so that I can completely recreate a new RemoteViews object. The reality is I really only need to be setting the text in one of the textviews in the RemoteViews each time I update. Is there anyway to just modify the RemoteViews that a particular widget is already using?

-Kurtis

推荐答案

首先,远程视窗不是一个视图。这是一组构建一个视图层次结构的说明。它被用来重建在另一个进程中的视图(应用程序窗口小部件不会在你的应用程序的进程中执行)。因此,它的序列化和可变的。

First, RemoteView is not a View. It's a set of instructions that build a View hierarchy. It is used to recreate a View in another process (App Widgets do not execute in your app's process). As such it's serializable and mutable.

所以,当你初始化远程视窗只存储对它的引用的地方,如在自定义AppWidgetProvider的领域。 下一次你需要它,从现场并在其上的改变的东西得到它。为了改变字符串中一个TextView使用<一个href="http://developer.android.com/reference/android/widget/RemoteViews.html#setString%28int,%20java.lang.String,%20java.lang.String%29"><$c$c>setString(..).

So, when you initialize a RemoteView just store a reference to it somewhere, e.g. in a field of your custom AppWidgetProvider. Next time you need it, get it from field and the change something on it. For changing the string in a TextView use setString(..).

remoteView.setString(textViewId, "setText", "some text for TextView")

这篇关于刚刚更新完全地创建一个新的小窗口RemoteViews呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆