我有一個應用程序小部件,我想向RemoteView
添加視圖(TextView
等),但它永遠不會顯示。
這裏去代碼:RemoteView addView無法正常工作
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
RemoteViews newView = new RemoteViews(context.getPackageName(), R.layout.widget_row_layout);
newView.setTextViewText(R.id.textUser, "1234");
views.addView(views.getLayoutId(), newView);
// Tell the AppWidgetManager to perform an update on the current App Widget
appWidgetManager.updateAppWidget(appWidgetId, views);
任何想法?
這是我落得這樣做:
RemoteViews newView = new RemoteViews(context.getPackageName(), R.layout.widget_row_layout);
newView.setTextViewText(R.id.textUser, "1234");
ComponentName thisWidget = new ComponentName(this,WidgetProvider.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(thisWidget, newView);
您應該將解決方案作爲答案添加並標記爲答案或選擇現有答案作爲解決方案。否則,這只是掛在那裏,因爲沒有回答... – 2010-11-27 23:48:07
是的,我同意hambonious,將其標記爲答案,並給這個人一些功勞! – JPM 2011-10-03 14:42:05