android - Wrong value for marker text passed to custom view -
i developing android application displays map. when loads, displays addresses , sets markers them.
when click on marker should display value in custom view. custom text received json parser, gets null value. when click on marker again, sets correct value.
when click on second marker display 1st marker value. when click on 2nd marker again displays correct value. process continues
here's code:
private class geocodertask extends asynctask<string, void, list<address>>{ private context maincontxt; geocoder geocoder; public geocodertask(context con){ maincontxt=con; } @override protected list<address> doinbackground(string... locationname) { geocoder geocoder = new geocoder(maincontxt); list<address> addresses = null; try { addresses = geocoder.getfromlocationname(locationname[0],1); } catch (ioexception e) { e.printstacktrace(); } return addresses; } @override protected void onpostexecute(list<address> addresses) { for(int i=0;i<addresses.size();i++){ address address = (address) addresses.get(i); latlng = new latlng(address.getlatitude(), address.getlongitude()); string addresstext = string.format("%s, %s", address.getmaxaddresslineindex() > 0 ? address.getaddressline(0) : "", address.getcountryname()); markeroptions = new markeroptions(); markeroptions.position(latlng); markeroptions.title(addresstext); if(i==0) { googlemap.animatecamera(cameraupdatefactory.zoomby(14),2000,null); googlemap.animatecamera(cameraupdatefactory.newlatlng(latlng)); } googlemap.addmarker(markeroptions); } googlemap.setonmarkerclicklistener(new onmarkerclicklistener() { @override public boolean onmarkerclick(marker marker_address) { location=marker_address.gettitle(); toast.maketext(getapplicationcontext(),location, toast.length_long).show(); new loadsingleproperty().execute(); //new loadimage().execute(); return false; } }); googlemap.setinfowindowadapter(new infowindowadapter() { @override public view getinfowindow(marker arg0) { return null; } @override public view getinfocontents(marker marker) { view mycontentview = getlayoutinflater().inflate( r.layout.custom_marker, null); tempnew_price=getprice(temptotal_price+"" +email); textview tvtitle = ((textview) mycontentview .findviewbyid(r.id.title)); // tvtitle.settext(location); tvsnippet = ((textview) mycontentview .findviewbyid(r.id.snippet)); ivproperty = ((imageview) mycontentview .findviewbyid(r.id.image_property)); tvtitle.settext(tempcovered_area+ " "+tempnew_price+system.getproperty("line.separator")+templocation); tvsnippet.settext("a "+ tempbedroom + " "+tempproperty_type); // new loadimage().execute(); ivproperty.setimagebitmap(bmp); return mycontentview; } }); googlemap.setoninfowindowclicklistener(new oninfowindowclicklistener() { @override public void oninfowindowclick(marker arg0) { intent intent = new intent(getbasecontext(), search_property_activity.class); intent.putextra("email", email); startactivity(intent); } }); } }
this loadsingle class coding.....
class loadsingleproperty extends asynctask<string, string, string> { @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(mainactivitymap.this); pdialog.setmessage("loading location. please wait..."); pdialog.setindeterminate(false); pdialog.setcancelable(false); pdialog.show(); } protected string doinbackground(string... args) { list<namevaluepair> params = new arraylist<namevaluepair>(); if(location!=null && !location.equals("")){ params.add(new basicnamevaluepair("location", location)); json= jsonparser.makehttprequest(url_loc_address, "get", params); } log.d("mylocation: ", json.tostring()); try { int success = json.getint(tag_success); if (success == 1) { address = json.getjsonarray(tag_all_address); //for (int = 0; < address.length(); i++) { jsonobject c = address.getjsonobject(0); templocation = c.getstring(tag_location); tempcovered_area=c.getstring(tag_covered_area); temptotal_price=c.getstring(tag_total_price); tempbedroom=c.getstring(tag_bedroom); tempproperty_type=c.getstring(tag_property_type); tempemail=c.getstring(tag_email); //} } else { } } catch (jsonexception e) { e.printstacktrace(); } return null; } protected void onpostexecute(string file_url) { pdialog.dismiss(); new geocodertask(mainactivitymap.this).execute(location); } }
help me friends ...thx in advance
create constructor loadsingleproperty
class loadsingleproperty extends asynctask<string, string, string> { marker mmarker; public loadsingleproperty(marker marker){ mmarker = marker; } . . . }
and pass marker object it.
new loadsingleproperty(marker_address).execute();
once parsing done set marker's title using settitle() method marker
mmarker.settitle(c.getstring(tag_property_type));
where this
tempproperty_type=c.getstring(tag_property_type);
don't forget refresh info window once title reset
how force refresh contents of markerinfowindow
you may want show sort of loading icon till time since you're performing network request.
edit:
in case you're using custom titleview, reference infowindowadapter object before setting adapter googlemap
infowindowadapter infowindowadapter = new infowindowadapter() {...
once parsing complete, info window view mmarker object calling
infowindowadapter.getinfowindow(mmarker);
find textview view obtained above , set text. refresh info window calling showinfowindow() update info window.
also please refer link.
the info window drawn not live view. view rendered image (using view.draw(canvas)) @ time returned. means subsequent changes view not reflected info window on map. update info window later (for example, after image has loaded), call showinfowindow()
Comments
Post a Comment