view - Replacing a TextView with the updated TextView Android -


i dynamically adding textview in activity layout. activity gets values activity using startactivityforresult , creates textview dynamically , add particular value it. problem there update button same activity when again value , come activity responsible displaying textview doesn't update textview , adds textview below previous textview int layout , keeps on adding without updating. know can set visibility gone removes textview child elements of layout or there way destroy text view , create in place?

my onactivityresult method:

protected void onactivityresult(int requestcode, int resultcode, intent intentdata) {         // todo auto-generated method stub         super.onactivityresult(requestcode, resultcode, intentdata);         if(requestcode == request_code && resultcode == result_ok){             locationlat = intentdata.getdoubleextra("locationlat", 0.0);             locationlng = intentdata.getdoubleextra("locationlang", 0.0);             location = locationlat + " "+locationlng;             if(location != ""){                 toast.maketext(this, location, toast.length_long).show();                 lblname = new textview(this);                 lblname.settext(location);                 lblname.setid(9);                 lblname.setlayoutparams(new layoutparams(layoutparams.wrap_content,layoutparams.wrap_content));                 linearlayout ll = (linearlayout) findviewbyid(r.id.llone);                 ll.addview(lblname, 5);                 button btnsetloc = (button) findviewbyid(r.id.getloc);                 btnsetloc.settext("change location");             }             else{                 toast.maketext(this, "location not set", toast.length_long).show();             }         }     } 

try check if lblname null or not if null create else update it

  protected void onactivityresult(int requestcode, int resultcode, intent intentdata) {             // todo auto-generated method stub             super.onactivityresult(requestcode, resultcode, intentdata);             if(requestcode == request_code && resultcode == result_ok){                 locationlat = intentdata.getdoubleextra("locationlat", 0.0);                 locationlng = intentdata.getdoubleextra("locationlang", 0.0);                 location = locationlat + " "+locationlng;                 if(location != ""){                     toast.maketext(this, location, toast.length_long).show();                     if(lblname==null) {                         lblname = new textview(this);                         lblname.setid(9);                         lblname.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content));                         linearlayout ll = (linearlayout) findviewbyid(r.id.llone);                         ll.addview(lblname, 5);                         button btnsetloc = (button) findviewbyid(r.id.getloc);                         btnsetloc.settext("change location");                     }                     lblname.settext(location);                 }                 else{                     toast.maketext(this, "location not set", toast.length_long).show();                 }             }         } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -