开发者

Android Widget, Handling Button Clicks !

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 onRec开发者_如何学Goeive(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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜