I have a widget that is designed to change its icon every time it receives broadcast updates. However, the widget can never correctly display its icon, displaying the text "Widget loading problem." Logcat message:
WARN/AppWidgetHostView(612): updateAppWidget couldn't find any view, using error view WARN/AppWidgetHostView(612): android.widget.RemoteViews$ActionException: can't find view: 0x7f060003
Code for my onUpdate:
public class ImageWidgetProvider extends AppWidgetProvider{ private static final String TAG = "Steve"; public static final int[] IMAGES = { R.drawable.ic_launcher_alarmclock, }; @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); } } }
Now, when I hover over R.id.image_in_widget, it discovers that its value is 0x7f060003 - a view that it cannot find according to Logcat. Using the second Log statement, I confirmed that IMAGES [imageNum] really refers to a random image from the IMAGES array. (In case it matters, it appears as a decimal value, not a hexadecimal value.) Any ideas what I'm doing wrong? Many thanks!
-
Edit: Here is the layout file for the widget where Image_in_widget ImageView is declared.
<?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>
source share