你好,我在我的Android小部件中遇到了一个非常奇怪的问题。我已经在许多地方深入研究了,但似乎无法找出问题所在。基本上,在我的小部件中调用pendingintent广播,并在onrecieve方法中成功捕获该意图。
然而,在onRecive方法中,当我尝试使用RemoteViews为我的组件设置文本时,文本不会更新,也不会调用任何错误。我已经附上了我的代码,任何帮助都将是极好的。
谢谢, M
package com.android.FirstWidget;import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RemoteViews;
public class ExampleAppWidgetProvider extends AppWidgetProvider {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.e("ds",intent.getAction());
Log.e("f","f");
if(intent.getAction().contains("1")){
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.wid);
views.setTextViewText(R.id.textView1,"heyheyhey");
Log.e("fssss","sssf");
}
super.onReceive(context, intent);
}
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch ExampleActivity
Intent intent = new Intent(context, ExampleAppWidgetProvider.class);
intent.setAction("1");
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.wid);
views.setOnClickPendingIntent(R.id.arrowLeft, pendingIntent);
views.setOnClickPendingIntent(R.id.arrowRight, pendingIntent);
//views.set
// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}