2010-07-30 47 views
4

我正在從AppWidget的buttonclick上啓動一項活動。用戶在活動中輸入一些數據,當用戶關閉活動時,我想更新在AppWidget上的TextView中輸入的數據用戶。任何想法如何做到這一點? 我已成功從AppWidget啓動活動,唯一的問題是更新AppWidget。正在更新AppWidget

回答

4

您可以使用RemoteViewsAppWidgetManager

AppWidgetManager manager = AppWidgetManager.getInstance(context); 

RemoteViews remoteViews = new RemoteViews(
    context.getPackageName(), R.layout.widget); 
remoteViews.setTextViewText(R.id.textBoxId, "new textbox content"); 

manager.updateAppWidget(appWidgetId, remoteViews); 
+0

在其中擴展的AppWidgetProvider我類的方法,我應該補充這一點? – 2010-07-31 15:46:34

+0

片段將更新小部件中的「TextView」。你寫到你想在用戶關閉一個Activity時更新你的Widget,這樣'Activity'的onPause方法就是一個好的例子。 – 2010-07-31 16:39:45

+0

@AmitChintawar appWidgetId從哪裏來? – ChristopheCVB 2012-01-30 21:19:21