Android Widget textView不会更新

时间:2011-10-17 12:08:14

标签: java android widget

我在开发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");这也是对的,因为我在代码的不同部分使用它,一切正常。相同的remoteViewsthisWidget声明。

为什么textView小部件不会更新?

0 个答案:

没有答案