【发布时间】:2011-02-24 07:58:48
【问题描述】:
我正在尝试向我的主 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>
【问题讨论】:
-
错误是什么?你能把堆栈跟踪吗?
-
小部件不显示,而是在小部件应该在的位置显示加载小工具时出现问题。 Log.e 上没有显示(我没有用自己的 Log 测试,因为我不知道要测试什么)
标签: android android-widget android-appwidget