2011-06-29 42 views
1

可以從主要活動中刪除小部件嗎?我正在寫小記事本,當某些筆記被刪除時,我想用這個筆記刪除小部件。如何從活動中刪除小部件?

編輯:

當我做這樣的事情:

Context context = getApplicationContext(); 
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); 
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); 
ComponentName thisWidget = new ComponentName(context, Widget.class); 
remoteViews.removeAllViews(R.id.widgetLayout); 
appWidgetManager.updateAppWidget(thisWidget, remoteViews); 

Widget是不可見的(因爲它沒有任何視圖),但我仍然可以點擊它等

我想在某些Activity中從主屏幕刪除小部件。

回答

0

ViewGroup有幾種removeView*(View)方法。或者,您可以撥打setVisibility(View.GONE)使窗口小部件從屏幕上消失而不實際刪除它。

Barry