title: Drag and drop a view
body: <p>I am trying to drag and drop a button on the screen.i can drag but when i drop the following error takes place.
  Logcat:</p>
  
  <pre><code>12-05 15:03:00.905: E/AndroidRuntime(1009): java.lang.IllegalArgumentException: Given view not a child of com.avigma.learning.DragLayer@44f5eda0
  12-05 15:03:00.905: E/AndroidRuntime(1009):     at android.view.ViewGroup.updateViewLayout(ViewGroup.java:1876)
  12-05 15:03:00.905: E/AndroidRuntime(1009):     at com.avigma.learning.DragLayer.onDrop(DragLayer.java:131)
  12-05 15:03:00.905: E/AndroidRuntime(1009):     at com.avigma.learning.DragController.drop(DragController.java:447)
  12-05 15:03:00.905: E/AndroidRuntime(1009):     at com.avigma.learning.DragController.onTouchEvent(DragController.java:424)
  12-05 15:03:00.905: E/AndroidRuntime(1009):     at com.avigma.learning.DragLayer.onTouchEvent(DragLayer.java:69)
  </code></pre>
  
  <p>xml:-</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;com.avigma.learning.DragLayer
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
  
      android:id="@+id/drag_layer"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  &lt;AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
  
    &lt;ImageView
          android:id="@+id/imageView1"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentRight="true"
          android:layout_alignParentTop="true"
         android:src="@drawable/b" /&gt;
  
    &lt;ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_x="-4dp"
        android:layout_y="2dp" &gt;
  
  
        &lt;AbsoluteLayout
            android:id="@+id/ll"
            android:layout_width="match_parent"
            android:layout_height="match_parent" &gt;
  
     //This button i am dragging and dropping
  &lt;Button
      android:id="@+id/button2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_x="84dp"
      android:layout_y="90dp"
      android:background="@null"
      android:text="B"
      android:textColor="#000000"
      android:textSize="35dp"
      android:textStyle="bold"
      android:typeface="serif" /&gt;
  
  &lt;/AbsoluteLayout&gt;
  
  
    &lt;/ScrollView&gt;
  
  &lt;/AbsoluteLayout&gt;
  &lt;/com.avigma.learning.DragLayer&gt;
  </code></pre>
  
  <p>I think i have to update the current view of movable object bcoz its refrencing drag layer its parent view but in my xml button current view is absolute layout.this error is in onDrop().I am providing its code:-</p>
  
  <pre><code> private boolean drop(float x, float y) {
  
      final int[] coordinates = mCoordinatesTemp;
      DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates);
  
      if (dropTarget != null) {
          dropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1],
                  (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
          if (dropTarget.acceptDrop(mDragSource, coordinates[0], coordinates[1],
                  (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo)) {
  
              dropTarget.onDrop(mDragSource, coordinates[0], coordinates[1],
                      (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
              mDragSource.onDropCompleted((View) dropTarget, true);
              return true;
          } else {
              mDragSource.onDropCompleted((View) dropTarget, false);
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>please help that what should i do to overcome this issue..or how to handle that button should not refrence drag layer its current parent view but absolute layout..I know whats the problem that either(1) move everything under one ViewGroup so all the movable views have the same parent view; (2) arrange to change the parent view of the view being moved when that view is dropped. But today I think I’d try what I suggested above: (3) in the view that is accepting the drop, make a copy of the view being dragged. Attach the copy as a child of that view. Go back to the original view and remove it from its parent.But how to code that to fix it please assist me...thanx..</p>