I want to add text views arranged in a linear layout to my widget on runtime. I do following:
LinearLayout l = new LinearLayout(context);
for (int i = 0; i < 10; i++) {
TextView t = new TextView(context);
t.setText("Hello");
l.addView(t); }
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
RemoteViews view = new RemoteViews (context.getPackageName(), l.getId());
views.addView(R.layout.main, view);
But when I add widget I get a Problem loading widget error. Seems like RemoteViews
has a problem with receiving a constructed view id as a parameter. But I can't make a reference to XML resource, because they are created on runtime. What is the proper way to populate the RemoteViews
with TextViews
on runtime?
Only xml resources can be used in RemoteViews. Views created on runtime should be based on predefined xml views.