java - Coordinate Issues with ImageButtons -


i programming android app/game allows users purchase buildings drag , drop imagebuttons (implementing drag , drop api). when user drags buildings around, coordinates stored in sqlite database when dropped.

say user buys 2 buildings: first colonyhut , second homehut. user places 2 buildings wherever wish, coordinates of buildings saved. issue when app closed , opened again. whenever app loads up, wherever second building (homehut) left first building (colonyhut) be.

i have been fighting issue forever , not why first building continually take coordinates of second building when second building moved.

here code check see if these 2 buildings have been purchased previously. if have dynamically created , inserted view.

    newhomehutoneid = prefs.getint("newhomehutone", 0);     if (newhomehutoneid != 0)     {         data.open();         homehutonex = data.gethomehutonex();         homehutoney = data.gethomehutoney();         data.close();         newhomehutframe = (framelayout) findviewbyid(r.id.bottomhalf);         newhomehutone = new imagebutton(getapplicationcontext());         newhomehutone.setbackgroundresource(r.drawable.homehut);         newhomehutone.settag("newhomehutone");         if (homehutonex == 0 && homehutoney == 0)         {             newhomehutone.setx(250);             newhomehutone.sety(250);         }//end if         else         {             newhomehutone.setx(homehutonex - (newhomehutone.getwidth()/2));             newhomehutone.sety(homehutoney - (newhomehutone.getheight()/2));         }//end else         newhomehutone.setontouchlistener(new buildingsclick());         findviewbyid(r.id.tophalf).setondraglistener(new homehutdrag(getapplicationcontext(), 1));         findviewbyid(r.id.bottomhalf).setondraglistener(new homehutdrag(getapplicationcontext(), 1));         framelayout.layoutparams  param1 = new framelayout.layoutparams(framelayout.layoutparams.wrap_content, framelayout.layoutparams.wrap_content);         newhomehutframe.addview(newhomehutone, param1);     }//end if      newcolonyhutoneid = prefs.getint("newcolonyhutone", 0);     if (newcolonyhutoneid != 0)     {         data.open();         colonyhutonex = data.getcolonyhutonex();         colonyhutoney = data.getcolonyhutoney();         data.close();         newcolonyhutframe = (framelayout) findviewbyid(r.id.bottomhalf);         newcolonyhutone = new imagebutton(getapplicationcontext());         newcolonyhutone.setbackgroundresource(r.drawable.colonyhut);         newcolonyhutone.settag("newcolonyhutone");         toast.maketext(getapplicationcontext(), "colonyhutone x: " + colonyhutonex + " y: " + colonyhutoney, toast.length_short).show();         if (colonyhutonex == 0 && colonyhutoney == 0)         {             newcolonyhutone.setx(250);             newcolonyhutone.sety(250);         }//end if         else         {             newcolonyhutone.setx(colonyhutonex - (newcolonyhutone.getwidth()/2));             newcolonyhutone.sety(colonyhutoney - (newcolonyhutone.getheight()/2));         }//end else         newcolonyhutone.setontouchlistener(new buildingsclick());         findviewbyid(r.id.tophalf).setondraglistener(new colonyhutdrag(getapplicationcontext(), 1));         findviewbyid(r.id.bottomhalf).setondraglistener(new colonyhutdrag(getapplicationcontext(), 1));         framelayout.layoutparams  param1 = new framelayout.layoutparams(framelayout.layoutparams.wrap_content, framelayout.layoutparams.wrap_content);         newcolonyhutframe.addview(newcolonyhutone, param1);     }//end if 

i have checked database , can see coordinates saved correctly , being saved correct imagebutton have no idea why keep happening.

if think need more information please let me know. lost , use ideas here.

i appreciate possible. guys!

this issue solved when realized not have separate ondraglisteners each drag , drop building. 1 ondraglistener can used , setup different way of identifying building being dragged in order save coordinates correct building.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -