views:

246

answers:

1

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

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?

+1  A: 

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.

Patrick Tsai
I'd like to add that this id should be Id of view under which you want to add your item.
Solvek