如何在不重建所有RemoteView的情况下部分更新应用程序窗口小部件中的视图

时间:2012-08-04 11:34:53

标签: android android-layout android-widget remoteview

我正在实现一个app小部件,我希望能够在小部件布局中更改单个视图的属性,而无需从头开始重建所有RemoteViews,这涉及到加载XML等等在某些情况下没有必要..有没有办法说“在当前小部件布局中由特定ID标识的视图上更新属性X”?我已经看到partiallyUpdateAppWidget类中有一个AppWidgetManager方法,但是我无法理解,也不是为了这个目的,也不是必须如何使用..你能帮助我吗?我是一个有用的链接或示例?

1 个答案:

答案 0 :(得分:4)

是的,您可以在partiallyUpdateAppWidge课程中使用AppWidgetManager t方法。 例如,如果要更新窗口小部件中的文本视图:

AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
rv = new RemoteViews(context.getPackageName(), R.layout.widgetlayout); 
rv.setTextViewText(R.id.ofTextViewInWidgetLayoutXML, "Hello World");
appWidgetManager.partiallyUpdateAppWidget(appWidgetIds, rv);

价: Just update a widget RemoteViews instead of completly creating a new one?