android widget click event -
i trying create app widget create wifi hot spot , have problem click event.
i have button , can't use onclicklistener. searched in google , here, , understand need send intent other class analyzes it, have problem this.
this mainactivity code: http://pastebin.com/pjhlkxgh
this wifiwidget code: http://pastebin.com/4nyt3u5u
and xml file is: http://pastebin.com/9cuurlbb
thank much!
it'd been easier developers stuff widgets through using objects instead of pendingintents. can quite tricky if coding first time.
public class mywidgetprovider extends appwidgetprovider { public static string widget_button = "com.anbe.turboandroid.widget_button"; private static final string sync_clicked = "automaticwidgetsyncbuttonclick"; @override public void onupdate(context context, appwidgetmanager appwidgetmanager, int[] appwidgetids) { remoteviews remoteviews; componentname watchwidget; remoteviews = new remoteviews(context.getpackagename(), r.layout.widget_layout); watchwidget = new componentname(context, mywidgetprovider.class); remoteviews.setonclickpendingintent(r.id.cache, getpendingselfintent(context, sync_clicked)); appwidgetmanager.updateappwidget(watchwidget, remoteviews); } @override public void onreceive(final context context, intent intent) { // todo auto-generated method stub super.onreceive(context, intent); if (sync_clicked.equals(intent.getaction())) { appwidgetmanager appwidgetmanager = appwidgetmanager.getinstance(context); final remoteviews remoteviews; componentname watchwidget; remoteviews = new remoteviews(context.getpackagename(), r.layout.widget_layout); watchwidget = new componentname(context, mywidgetprovider.class); appwidgetmanager.updateappwidget(watchwidget, remoteviews); // stuff here } } protected pendingintent getpendingselfintent(context context, string action) { intent intent = new intent(context, getclass()); intent.setaction(action); return pendingintent.getbroadcast(context, 0, intent, 0); } }
you can write tasks in commented part.
cheers gabriel
Comments
Post a Comment