Just update the RemoteViews widget instead of completely creating a new one?

So, in my onUpdate method in my AppWidgetProvider class, I ended up executing a non-trivial amount of code to completely restore the new RemoteViews object. The reality is that I really only need to set the text in one of the text views in RemoteViews every time I update. Do I need to modify the RemoteViews that a particular widget already uses?

-Kurtis

+3
source share
3 answers

-, RemoteView . , . ( ). .

, RemoteView, -, . AppWidgetProvider. , , - . TextView setString(..).

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

2013 , API. WidgetProvider, :

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

, remoteView.setString, remoteView.setTextViewText

+16

You can update deleted views and then call

ComponentName componentName= new ComponentName(context, YourClass.class);
AppWidgetManager.getInstance(context).updateAppWidget(componentName, remoteViews);

on which AFAIK should update the widget

0
source

All Articles