Android Widget textView 不更新
我在开发 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 小部件不更新?
I'm having difficulties with developing an onclick
widget textView update. Here is the code:
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
action itself works because when I remove appWidgetManager.updateAppWidget(thisWidget, remoteViews);
Toast pops out.
remoteViews.setTextViewText(R.id.textView1, "asdasd");
This is right too because I use it in different part of code and everything works. Same remoteViews
and thisWidget
declarations.
Why doesn't the textView widget update?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论