Quiero agregar vistas de texto dispuestas en un diseño lineal a mi widget en tiempo de ejecución. Hago lo siguiente:Android Widgets: Cómo agregar vistas a RemoteViews en tiempo de ejecución
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);
Pero cuando agrego el widget me sale un problema al cargar el error del widget. Parece que RemoteViews
tiene un problema al recibir una ID de vista construida como parámetro. Pero no puedo hacer una referencia al recurso XML, porque se crean en tiempo de ejecución. ¿Cuál es la forma correcta de llenar el RemoteViews
con TextViews
en tiempo de ejecución?