4

I am implementing Drag and Drop from ListView to another ListView,i got sample app here,

How to Drag drop Listview item to another Listview

using above app created one app,It's working fine up to 4th image of ListView.In my view By default ListView display up to 3rd position(means 0,1,2,3),if i drag the 2nd position from first ListView and drop in second ListView,It's display same image.When i scroll down,positions is 4,5,6,7.if i drag 6th position,it's takes 2nd position. please help me

Community
  • 1
  • 1
suresh
  • 415
  • 3
  • 9
  • 20

1 Answers1

0

You should use a for loop .Then give the count of number to the list and check with each count.Check if the id's of the loops are the same if they are different you will directly get different images at the stored place.

public boolean onTouchEvent(MotionEvent ev) {
        // TODO Auto-generated method stub
        final int action = ev.getAction();
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();  

        if (action == MotionEvent.ACTION_DOWN && x < this.getWidth()/4) {
            mDragMode = true;
        }

        if (!mDragMode) 
            return super.onTouchEvent(ev);

        switch (action) {
            case MotionEvent.ACTION_DOWN:
                mStartPosition = pointToPosition(x,y);
                if (mStartPosition != INVALID_POSITION) {
                    int mItemPosition = mStartPosition - getFirstVisiblePosition();
                    mDragPointOffset = y - getChildAt(mItemPosition).getTop();
                    mDragPointOffset -= ((int)ev.getRawY()) - y;
                    startDrag(mItemPosition,y);
                    drag(0,y);// replace 0 with x if desired
                }   
                break;
            case MotionEvent.ACTION_MOVE:
                drag(0,y);// replace 0 with x if desired
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
            default:
                mDragMode = false;
                mEndPosition = pointToPosition(x,y);
                stopDrag(mStartPosition - getFirstVisiblePosition());
                if (mDropListener != null && mStartPosition != INVALID_POSITION && mEndPosition != INVALID_POSITION) 
                     mDropListener.onDrop(mStartPosition, mEndPosition);
                break;
        }
        return true;
    }

this will help u to push the code in from one location to another.And on the Drag method specify the x&y where you want to push it.

Terril Thomas
  • 1,486
  • 13
  • 32