Reputation: 58
i'm having some ImageButtons on my widget and i'm handling them using my own action strings, none of them is a config. button .. i'm not having in my xml design an update period since i don't need to update anything, so all my handling is in the onReceive(context, intent) method! but still wouldn't work .. i still don't really get the way we handle button clicks in widgets, can anyone help?? even with the core concept of handling buttons .. Thanks!
Upvotes: 0
Views: 436
Reputation: 11829
Put this in the onUpdate
method of your AppWidgetProvider:
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widgetmain);
Intent configIntent = new Intent(context, Call1.class);
configIntent.setAction(ACTION_WIDGET_CONFIGURE);
PendingIntent configPendingIntent = PendingIntent.getActivity(context, REQUEST_CODE_ONE, configIntent, 0);
remoteViews.setOnClickPendingIntent(R.id.ImageButton01, configPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
Variables outside the method:
public static String ACTION_WIDGET_CONFIGURE = "ConfigureWidget";
private static final int REQUEST_CODE_ONE = 10;
In this code when you click on ImageButton01 of the widget, it launches Call1.class.
Upvotes: 1