RemoteViews addView function returns errors on AppWidget
I'm trying to create a AppWidget that displays a number of items (which can change). I'd like to generate TextViews dynamically, I assume I do this by using:
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.id.widgetmain);
RemoteViews newView = new RemoteViews(context.getPackageName(), R.id.widgetite开发者_运维技巧m);
updateViews.addView(0, newView);
But this returns a Problem loading widget
error. The widgetitem.xml is just a TextView within a LinearLayout. The widgetmain.xml is two TextViews within a LinearLayout.
What am I doing wrong?
updateViews.addView(0, newView);
You should specify correct viewId rather than 0 as the parent of your widgetitem. For your exmaple, you can probably add an empty container under widgetmain for this purpose.
精彩评论