How to partially update views in application widgets without restoring all deleted applications

I am implementing an application widget, and I would like to be able to change the property of one view in the widget layout without rebuilding everything RemoteViewsfrom scratch, which is related to loading XML, etc., and this is not necessary in some cases .. Is there a way to say " change property X to the view identified by a specific identifier in the current widget layout "? I saw that there is a method partiallyUpdateAppWidgetin the class AppWidgetManager, but I can’t understand, and if it is intended for this purpose, then how should it be used. Can you help me or point me to a useful link or example?

+5
source share
1 answer

Yes, you can use the partiallyUpdateAppWidget method in the class AppWidgetManager. For example, if you want to update the text view inside the widget:

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

Ref: Just updating the RemoteViews widget instead of creating a whole new one?

+3
source

All Articles