Hi,
I have a widget that is meant to change its icon every time it receives the Update broadcast. However, the widget never manages to display its icon properly, displaying the text "Problem loading widget". The Logcat message is:
WARN/AppWidgetHostView(612): updateAppWidget couldn't find any view, using error view
WARN/AppWidgetHostView(612): android.widget.RemoteViews$ActionException: can't find view: 0x7f060003
The code for my onUpdate is:
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);
}
}
}
Now when I hover the mouse over "R.id.image_in_widget" it brings up that its value is equal to 0x7f060003 - the view that it can't find according to Logcat. Using the second Log statement, I verified that IMAGES[imageNum] does indeed refer to a random image from the IMAGES array. (In case it matters, it comes out as a decimal value rather than a hexadecimal one.) Any ideas what I'm doing wrong? Thanks a lot!
--
Edit: Here is the layout file for the widget, where the 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>