当我想更新我的ImegeView时,我看到“问题加载小部件”;
我的main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="280dp"
android:layout_height="120dp"
android:background="@drawable/widget_bg"
>
<ImageView
android:name="@+id/image_in_widget"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</AbsoluteLayout>
我的Widget.java
package endoftheworld.wid;
//some imports
public class Widget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.main);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.pulse);
updateViews.setImageViewBitmap(R.id.image_in_widget,bitmap);
appWidgetManager.updateAppWidget(appWidgetIds, updateViews);
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
}
在DDMS中我可以看到
AppWidgetHostView(128): android.widget.RemoteViews$ActionException: can't find view: 0x7f060000
但我在R.java中有0x7f060000
//....
public static final class id {
public static final int image_in_widget=0x7f060000;
}
//...
我使用Android平台2.3.1 API级别9 CPU / ABI ARM(armeabi)。
什么是伎俩?
答案 0 :(得分:0)
您传递给R.layout.main
的{{1}}布局没有ID RemoteViews
的任何视图。也许您打算传递不同的布局,或者该布局中的R.id.image_in_widget
可能包含错误的ID。