How to drag multiple images by extending View in Android?
<p>I am working on drag and drop of images.I developed <code>MyView</code> class by extending <code>View</code>  and I have overridden <code>onDraw</code> method and now I am able to drag single image.</p>

<p>But when it comes to multiple images I am not able to drag the required image. When I try to do it,every image is being dragged.</p>

<p>Here is My Code:</p>

<p>public class Home extends Activity {</p>

<pre><code>public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(new MyView(getApplicationContext()));

 }
public static class MyView extends View{
     private Drawable mIcon,mIcon1;
     private TextView tv;
    private float mLastTouchX;
    private float mLastTouchY;
    private float mPosX;
    private float mPosY;
    public MyView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    mIcon=getResources().getDrawable(R.drawable.icon);
    mIcon.setBounds(0,0,mIcon.getIntrinsicWidth(),mIcon.getIntrinsicHeight());

    mIcon1=getResources().getDrawable(R.drawable.icon);

    mIcon1.setBounds(40,40,150,100);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.save();
        canvas.translate(mPosX,mPosY);
        tv.draw(canvas);
        mIcon.draw(canvas);
        mIcon1.draw(canvas);
        canvas.restore();   
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
     switch(event.getAction())
     {
     case MotionEvent.ACTION_DOWN: {
            final float x = event.getX();
            final float y = event.getY();
            mLastTouchX = x;
            mLastTouchY = y;
            break;
        }     
        case MotionEvent.ACTION_MOVE: {
            final float x = event.getX();
            final float y = event.getY();
            final float dx = x - mLastTouchX;
            final float dy = y - mLastTouchY;
            mPosX += dx;
            mPosY += dy;
            mLastTouchX = x;
            mLastTouchY = y;
            invalidate();
            break;
        }
     }
        return true;
    }
}
</code></pre>

<p>}</p>

<p>Thanks</p>
