android - Is there any way to handle a button from a different activity? -
referring image below. want update map when user clicks view map button. however, since part of expandable list view, in it's own class, while map in fragment activity.
is there way listen button click , update map accordingly activity?
thanks!
here's have far. tried getting parameter via
expandablelistelement.polylinepass
but not give me can't update map. question, map update when values changed polyline, or need setup map again?
map display activity:
public class offlineviewer extends fragmentactivity { private void setupmap() { list<latlng> listtemp = util.decodepoly(expandablelistelement.polylinepass); for(int l=0;l<listtemp.size() - 1;l++){ list.add(listtemp.get(l)); if(l==0) { } } int listsize = list.size(); //get polyline expandable list elements (int = 0; < list.size() - 1; i++) { latlng src = list.get(i); latlng dest = list.get(i + 1); polyline line = mmap.addpolyline(new polylineoptions() //mmap map object .add(new latlng(src.latitude, src.longitude), new latlng(dest.latitude,dest.longitude)) .width(5).color(color.blue).geodesic(true)); } ... }
expandablelistelement activity:
public class expandablelistelement extends relativelayout { public expandablelistelement(context context, string routename, string mode, string dist, string routeid, string start, string end, final string polyline) { super(context); mcontext = context; settextviewelements(routename, mode, dist, routeid, start, end, polyline); button randbutton = new button(mcontext); randbutton.settext("view map"); randbutton.setid(midpool); randbutton.setonclicklistener(new button.onclicklistener() { public void onclick(view v) { polylinepass = polyline; } }); ... }
you can handle activity class. lets map in 1 fragment , button in on. both "hosted" same activity.
let activity have method , sure public:
class myactivity extends activity { private fragment fragment1; //the frag button private fragment fragment2; //the frag map public void updatemap(string argument) { if(fragment2 != null) fragment2.update(argument); } }
then fragment button (fragment1), call ((myactivity) getactivity()).updatemap(argument) update map:
class fragment1 extends fragment implements onclicklistener{ // called on button click void onclick(...) { ((myactivity) getactivity()).updatemap(argument) } }
your second fragment needs public method upting map:
class fragment1 extends fragment implements onclicklistener{ public void updatemap(string arguments) { // update map... } }
this strategy can used in lists
Comments
Post a Comment