What's the best way of getting input from appwidget
. I know that I can use setOnClickPendingIntent
method from RemoteViews
, but I don't want that! Is there any alternative ways ?
P.S. When i'm trying to register onClick
listener in Xml (<ImageView android:onClick="myHandler" ... />
) it's throws an exception.
W/AppWidgetHostView( 178): android.view.InflateException: Binary XML file line #11: Error inflating class android.widget.Button
W/AppWidgetHostView( 178): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
W/AppWidgetHostView( 178): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
W/AppWidgetHostView( 178): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
W/AppWidgetHostView( 178): at android.v开发者_运维问答iew.LayoutInflater.rInflate(LayoutInflater.java:618)
W/AppWidgetHostView( 178): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
W/AppWidgetHostView( 178): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
W/AppWidgetHostView( 178): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
W/AppWidgetHostView( 178): at android.widget.RemoteViews.apply(RemoteViews.java:900)
W/AppWidgetHostView( 178): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:208)
W/AppWidgetHostView( 178): at com.htc.launcher.LauncherAppWidgetHostView.updateAppWidget(LauncherAppWidgetHostView.java:116)
W/AppWidgetHostView( 178): at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:243)
W/AppWidgetHostView( 178): at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:72)
W/AppWidgetHostView( 178): at android.os.Handler.dispatchMessage(Handler.java:99)
W/AppWidgetHostView( 178): at android.os.Looper.loop(Looper.java:123)
W/AppWidgetHostView( 178): at android.app.ActivityThread.main(ActivityThread.java:4595)
W/AppWidgetHostView( 178): at java.lang.reflect.Method.invokeNative(Native Method)
W/AppWidgetHostView( 178): at java.lang.reflect.Method.invoke(Method.java:521)
W/AppWidgetHostView( 178): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
W/AppWidgetHostView( 178): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
W/AppWidgetHostView( 178): at dalvik.system.NativeStart.main(Native Method)
W/AppWidgetHostView( 178): Caused by: java.lang.reflect.InvocationTargetException
W/AppWidgetHostView( 178): at android.widget.Button.<init>(Button.java:65)
W/AppWidgetHostView( 178): at java.lang.reflect.Constructor.constructNative(Native Method)
W/AppWidgetHostView( 178): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
W/AppWidgetHostView( 178): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
W/AppWidgetHostView( 178): ... 19 more
W/AppWidgetHostView( 178): Caused by: java.lang.IllegalStateException: The android:onClick attribute cannot be used within a restricted context
W/AppWidgetHostView( 178): at android.view.View.<init>(View.java:2005)
W/AppWidgetHostView( 178): at android.widget.TextView.<init>(TextView.java:335)
W/AppWidgetHostView( 178): at android.widget.Button.<init>(Button.java:69)
W/AppWidgetHostView( 178): ... 23 more
I know that I can use setOnClickPendingIntent method from RemoteViews, but I don't want that!
You do not have a choice. It is your only input option through API Level 10 (Gingerbread).
For API Level 11 and higher (Honeycomb, etc.), you can create app widgets that contain ListView
, GridView
, and StackView
. For those, you can provide another PendingIntent
that will be invoked when items in the list (or grid or stack) are clicked. This will work similarly to setOnClickPendingIntent()
.
精彩评论