Widget host app with custom view - onClick is not triggered in the app widget.
Posted
by Dennis K
on Stack Overflow
See other posts from Stack Overflow
or by Dennis K
Published on 2010-03-11T17:14:25Z
Indexed on
2010/03/11
17:19 UTC
Read the original article
Hit count: 264
android
|android-widget
I'm writing an app that will host widgets. The app has custom view (which probably is the source of issue). I obtain AppWidgetHostView like this
private AppWidgetHostView widget;
...
AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
widget = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
widget.setAppWidget(appWidgetId, appWidgetInfo);
mView.addWidget(widget, appWidgetInfo);
mView.addWidget() basically just remembers this AppWidgetHostView instance and then draws it directly onto canvas. Visually everything is fine - I can see the actual widget. But the issue is with reacting on UI events. Please advise what needs to be done in the parent view in order to correctly trigger handlers in the widgets like onClick().
Notes:
I used standard widgets which normally react on click events. None worked.
I also created my own test widget with listener (via views.setOnClickPendingIntent(R.id.appwidget_text, pending);) and onClick() is successfully triggered if the widget is added on Homescreen, but doesn't work in my app.
mView correctly detects click event and I tried to call widget.performClick() there, which returns false meaning onClickListener is not registered in the widget. But according to source mAppWidgetHost.createView() would call updateAppWidget which would register its onClick listener..
Please advise where to look at. Thanks
© Stack Overflow or respective owner