I am trying to impement Androids drag and drop on my gridview. I set a dragListener for each view in the grid adapter. It works perfectly when the grid isn't long enough to be scrollable or if it is scrollable as long as the first view in the grid is visible. When scrolled it is moving the actions down a position for however many views are not visible at the top instead of being at the correct position.
GridView set DragListener inside of the adapter:
ImageView i = new ImageView;
i.setImageResource(ImageList.get(position));
i.setOnDragListener(new MyDragImageListener(position));
return i;
MyDragListener:
public class MyDragImageListener implements OnDragListener{
int imagePosition;
public MyDragImageListener(int position) {
imagePosition = position;
}
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
Log.i("DRAG Started", "" + imagePosition);
break;
case DragEvent.ACTION_DRAG_ENTERED:
Log.i("DRAG Entered", "" + imagePosition);
ImageView imageEnter = (ImageView) Grid.getChildAt(imagePosition);
imageEnter.setBackgroundColor(Color.argb(155, 100, 200, 255));
break;
case DragEvent.ACTION_DRAG_EXITED:
Log.i("DRAG Exited", "" + imagePosition);
ImageView imageExit = (ImageView) Grid.getChildAt(imagePosition);
imageExit.setBackgroundColor(Color.argb(0, 0, 0, 0));
break;
case DragEvent.ACTION_DROP:
Log.i("DRAG Dropped", "" + imagePosition);
break;
case DragEvent.ACTION_DRAG_ENDED:
Log.i("DRAG Ended", "" + imagePosition);
default:
break;
}
return true;
}
}