Updateブロードキャストを受信するたびにアイコンを変更するためのウィジェットがあります。ただし、ウィジェットがアイコンを正しく表示できず、「ウィジェットの読み込みに問題があります」というテキストが表示されます。Logcatメッセージは次のとおりです。
WARN/AppWidgetHostView(612): updateAppWidget couldn't find any view, using error view
WARN/AppWidgetHostView(612): android.widget.RemoteViews$ActionException: can't find view: 0x7f060003
私のonUpdateのコードは次のとおりです。
public class ImageWidgetProvider extends AppWidgetProvider{
private static final String TAG = "Steve";
public static final int[] IMAGES = { R.drawable.ic_launcher_alarmclock,
/*and many more*/};
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds){
for (int appWidgetId : appWidgetIds) {
Log.d(TAG, "onUpdate:");
int imageNum = (new java.util.Random().nextInt(IMAGES.length));
Log.d(TAG, Integer.toString(IMAGES[imageNum]));
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget);
remoteView.setImageViewResource(R.id.image_in_widget, IMAGES[imageNum]);
appWidgetManager.updateAppWidget(appWidgetId, remoteView);
}
}
}
ここで、マウスを「R.id.image_in_widget」に合わせると、その値が0x7f060003に等しいことが表示されます。これは、Logcatによると見つからないビューです。2番目のLogステートメントを使用して、IMAGES[imageNum]が実際にIMAGES配列からのランダムな画像を参照していることを確認しました。(重要な場合は、16進値ではなく10進値として出力されます。)私が間違っていることについて何か考えはありますか?どうもありがとう!
-
編集:これは、image_in_widgetImageViewが宣言されているウィジェットのレイアウトファイルです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:name="@+id/image_in_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>