更新Android主屏幕TextView
问题描述:
我们如何更新AppWidgetProvider的onReceive方法上的主屏幕小部件的视图?更新Android主屏幕TextView
我想更新我的主屏幕小部件的TextView,但似乎我无法访问onReceive方法上的我的AppWidgetProvider TextView。
这里是一个示例代码我的onReceive
public void onReceive(Context context,Intent intent) {
final String action = intent.getAction();
if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
final int appWidgetId = intent.getExtras().getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
this.onDeleted(context, new int[] { appWidgetId });
}
} else {
if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
String msg = "null";
try {
msg = intent.getStringExtra("msg");
} catch (NullPointerException e) {
}
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
// code for gathering the text to update the TextView
}
}
super.onReceive(context, intent);
}
答
无法更新的TextView。您只能构建完整的新窗口小部件布局(RemoteViews)并将其发布到主屏幕。
有没有办法,其中如果我们点击主屏幕上的按钮,它会更新其中的TextView? – user364556 2010-06-12 07:56:34
不幸的是没有。只发送意图广播接收器并重建新的RemoteViews。 – Fedor 2010-06-12 08:35:27