我在开发onclick
小部件textView更新时遇到了困难。这是代码:
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
thisWidget = new ComponentName(context, Widget.class);
if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
try {
tytuly = intent.getStringArrayExtra("tytuly");
contenty = intent.getStringArrayExtra("contenty");
} catch (NullPointerException e) {
Log.e("Error", "msg = null");
}
String countwrite = Integer.toString(i);
Toast.makeText(context, countwrite, Toast.LENGTH_SHORT).show();
remoteViews.setTextViewText(R.id.textView1, "asdasd");
remoteViews.setTextViewText(R.id.textView2, "sdv cxadsa");
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
appWidgetManager.updateAppWidget(thisWidget, remoteViews);
}
Onclick
操作本身有效,因为当我删除appWidgetManager.updateAppWidget(thisWidget, remoteViews);
Toast弹出时。
remoteViews.setTextViewText(R.id.textView1, "asdasd");
这也是对的,因为我在代码的不同部分使用它,一切正常。相同的remoteViews
和thisWidget
声明。
为什么textView小部件不会更新?