好吧,我自己解決了它..經過大量的試驗和錯誤。我認爲我在這裏發佈我的解決方案。
我創建了一個xml.file,我將其稱爲entity.xml,它包含我需要表示一個位置的視圖。我還創建了另一個名爲widgetLayout.xml的xml文件,其中包含一個空的linearLayout。
然後我這樣做,當我想動態創建小部件佈局。
RemoteViews main = new RemoteViews(getApplicationContext().getPackageName(), R.layout.widget_layout);
main.removeAllViews(R.id.main);
RemoteViews location = new RemoteViews(getApplicationContext().getPackageName(), R.layout.entity);
location.setTextViewText(R.id.SpotName, "loc");
RemoteViews location2 = new RemoteViews(getApplicationContext().getPackageName(), R.layout.entity);
spot1.setTextViewText(R.id.SpotName, "loc2");
main.addView(R.id.main, location);
main.addView(R.id.main, location2);
int[] allWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
AppWidgetManager.getInstance(getApplicationContext()).updateAppWidget(allWidgetIds[0], main);
祝賀修復!如果可以,請確保將您的答案標記爲「已接受」,以便您的解決方案可供具有相同問題的其他人訪問。乾杯〜 – 2012-03-27 20:34:31