Skip to content Skip to sidebar Skip to footer

How Defined Target For Drag And Drop Image

in my program i 4 imageview, imageview1 and imageview2 should drag and drop to imageview3 and imageview4 imageview1 should drop only in imageview3 and if droped another place shoul

Solution 1:

in onTouchListener i should X and Y that image i drag like this

 private final class MyTouchListener implements OnTouchListener {
    public boolean onTouch(View view, MotionEvent event) {

        final int mX = (int) event.getX();
       final int mY = (int) event.getY();
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        ClipData data = ClipData.newPlainText("", "");
        DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
        view.startDrag(data, shadowBuilder, view, 0);
        view.setVisibility(View.INVISIBLE);
        return true;
      } else {
        return false;
      }
    }
  }

and in action_drop i take X and Y that image i release that like this

 case DragEvent.ACTION_DROP:
         v.getX();
         v.getY();

        // Dropped, reassign View to ViewGroup
            View view = (View) event.getLocalState();
            //ClipData cd =  event.getClipData();
            //Item item = cd.getItemAt(0);
            //String resp = item.coerceToText(context).toString();


            //stop displaying the view where it was before it was dragged
            view.setVisibility(View.INVISIBLE);

            //view dragged item is being dropped on
            ImageView dropTarget = (ImageView) v;

            //view being dragged and dropped
            ImageView dropped = (ImageView) view;

        //  dropped.setEnabled(false);

            //update the text in the target view to reflect the data being dropped
            dropTarget.setBackgroundDrawable(view.getBackground());


            dropTarget.setTag(dropped.getId());


        break;

how i take X and Y other image?


Post a Comment for "How Defined Target For Drag And Drop Image"