title: Coordinate Issues with ImageButtons
body: <p>I am programming an android app/game that allows users to purchase buildings that are drag and drop imagebuttons (implementing the drag and drop api). When a user drags the buildings around, the coordinates are immediately stored in an sqlite database when they are dropped. </p>
  
  <p>Say the user buys two buildings: the first is a colonyHut and the second is homeHut. The user then places the two buildings wherever they wish, thus the coordinates of the buildings are saved. The issue is when the app is closed and then opened again. Whenever the app loads back up, wherever the second building (homeHut) was left previously will now be where the first building (colonyHut) will be.</p>
  
  <p>I have been fighting this issue forever and I am not certain why the first building will continually take the coordinates of the second building when the second building is moved. </p>
  
  <p>Here is the code where I check to see if these two buildings have been purchased previously. If they have they are dynamically created and inserted into the view. </p>
  
  <pre><code>    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 &amp;&amp; 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 &amp;&amp; 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
  </code></pre>
  
  <p>I have checked the database and I can see that the coordinates are saved correctly and are being saved for the correct imageButton so I have no idea why this would keep happening.</p>
  
  <p>If you think that you need more information please let me know. I am lost and could really use any ideas here.</p>
  
  <p>I appreciate any help possible. Thanks guys!</p>