android - ListView Item ID homescreen widget -
i have homescreen widget
listview
how can obtain number of current item
clicked: i've tried following way: insite custom class extends appwidgetprovider
public void onupdate(context ctxt, appwidgetmanager mgr, int[] appwidgetids) { (int i=0; i<appwidgetids.length; i++) { intent svcintent=new intent(ctxt, widgetservice.class); svcintent.putextra(appwidgetmanager.extra_appwidget_id, appwidgetids[i]); svcintent.setdata(uri.parse(svcintent.touri(intent.uri_intent_scheme))); remoteviews widget=new remoteviews(ctxt.getpackagename(), r.layout.widget); widget.setremoteadapter(appwidgetids[i], r.id.contacts, svcintent); intent clickintent=new intent(ctxt, appwidget.class); clickintent.setaction(action_widget_refresh); clickintent.putextra(appwidgetmanager.extra_appwidget_ids, appwidgetids[i]); pendingintent pi=pendingintent.getbroadcast(ctxt, 0 , clickintent, pendingintent.flag_update_current); widget.setpendingintenttemplate(r.id.contacts, pi); mgr.updateappwidget(appwidgetids[i], widget); } super.onupdate(ctxt, mgr, appwidgetids); } @override public void onreceive(context context, intent intent) { log.i("gotcha","receive"); if (intent.getaction().equals(action_widget_refresh)) { intent callintent = new intent(intent.action_call); bundle extras = intent.getextras(); int extrass= -1; if(extras!=null) { extrass = extras.getint(appwidgetmanager.extra_appwidget_ids); } log.i("receive", integer.tostring(extrass) ) ; // here i've expected see item id }
but it's not helped. i've see different numbers (not items id)
how can obtain them?
the problem is
pendingintent pi=pendingintent.getbroadcast(ctxt, 0 , clickintent, pendingintent.flag_update_current);
because if give 0 requestcode
, , flag flag_update_current
, list items refer same pendingintent
update lasted.
so give different requestcode pendingintent solve problem, please use
pendingintent pi=pendingintent.getbroadcast(ctxt, appwidgetids[i] , clickintent, pendingintent.flag_update_current)`
instead. , set onclickfillintent remoteview in adapter.getviewat()
remoteviews rv = new remoteviews(pkg, r.layout.item); intent = new intent().putextra("position", position); rv.setonclickfillinintent(r.id.item, i);
then can retrieve appwidget id , list item position.
Comments
Post a Comment