我正在尝试向我的主 RemoteViews 添加一个视图,但我不断收到加载小工具错误的问题。这是xmls和代码,将不胜感激。
public class WidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
ComponentName thisWidget = new ComponentName(context, WidgetProvider.class);
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget_main);
RemoteViews bookmark = new RemoteViews(context.getPackageName(), R.layout.widget_items);
updateViews.addView(R.id.view_container, bookmark);
appWidgetManager.updateAppWidget(thisWidget, updateViews);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout_widget"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/widget_4x4_portrait"
>
<?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="wrap_content">
<LinearLayout
android:id="@+id/view_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- New views will be added here at runtime -->
</LinearLayout>
</LinearLayout>