Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to partially update views in an app widget without rebuilding all the RemoteViews

I'm implementing an app widget and I'd like to be able to change the property of a single view in the widget layout, without rebuilding all the RemoteViews from scratch, which involves loading XML etc and which is not necessary in some circumstances.. Is there a way to say "update property X on view identified by a specific ID in the current widget layout"? I've seen that there is a partiallyUpdateAppWidget method in the AppWidgetManager class but I can't understand nor if it is meant for this purpose neither how it must be used.. Can you help me or point me to a useful link or example?

like image 516
Gianni Costanzi Avatar asked Oct 07 '22 00:10

Gianni Costanzi


1 Answers

Yes, you can use partiallyUpdateAppWidget method in the AppWidgetManager class. As an example, if you want to update a text view inside a 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 update a widget RemoteViews instead of completly creating a new one?

like image 172
Yanling Avatar answered Oct 13 '22 02:10

Yanling