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

前端 未结 3 1716
傲寒
傲寒 2021-02-10 07:35

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

3条回答
  •  旧巷少年郎
    2021-02-10 08:11

    This is the 2013 update if you are using current API's. In your WidgetProvider class' method that will perform an update:

    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);
    

    Note that it is no longer remoteView.setString but remoteView.setTextViewText

提交回复
热议问题