For a widget I use a simple layout which contains a TableLayout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow >
(...)
</TableRow>
</TableLayout>
But when a I want to update its content by creating a RemoteViews
RemoteViews eventElementLayout = new RemoteViews( this.getPackageName(), R.layout.widget_events_element );
I got an exception telling me that TableLayout
is not allowed to be inflated.
12-04 01:36:12.548: WARN/AppWidgetHostView(195): updateAppWidget couldn't find any view, using error view
12-04 01:36:12.548: WARN/AppWidgetHostView(195): android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.TableLayout
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.widget.RemoteViews.apply(RemoteViews.java:930)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.widget.RemoteViews$ViewGroupAction.apply(RemoteViews.java:513)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.widget.RemoteViews.performApply(RemoteViews.java:955)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.widget.RemoteViews.apply(RemoteViews.java:932)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:219)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:250)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:73)
12-04 01:36:开发者_运维问答12.548: WARN/AppWidgetHostView(195): at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.os.Looper.loop(Looper.java:123)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at java.lang.reflect.Method.invokeNative(Native Method)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at java.lang.reflect.Method.invoke(Method.java:521)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at dalvik.system.NativeStart.main(Native Method)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): Caused by: android.view.InflateException: Binary XML file line #2: Class not allowed to be inflated android.widget.TableLayout
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.view.LayoutInflater.failNotAllowed(LayoutInflater.java:525)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.view.LayoutInflater.createView(LayoutInflater.java:472)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): ... 19 more
Why ?
Thanks in advance
App widgets only allow limited list of layout and view widget types that can be used within them. It looks like TableLayout
isn't supported. From Google developers documentation:
A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:
* FrameLayout * LinearLayout * RelativeLayout
And the following widget classes:
* AnalogClock * Button * Chronometer * ImageButton * ImageView * ProgressBar * TextView
Descendants of these classes are not supported.
精彩评论