As I know, if my onTouch
method returns false
, after the initial ACTION_DOWN case it does not start tracking the movement, and if I return true
, it does. But I have some cases when I need to stop tracking the movement from some moment. How do I achieve this? I tried to returning false when my condition holds, but it continues to run into that case. How to cancel or stop the motion event?
Here is the code I have for my drag and drop application, and when the X is less than 100, I just want to stop dragging. How can I achieve this?
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
imageTouchX = (int) event.getRawX() - (int) img.getX();
imageTouchY = (int) event.getRawY() - (int) img.getY();
break;
case MotionEvent.ACTION_MOVE:
int x_cord = (int) event.getRawX();
int y_cord = (int) event.getRawY();
img.setX(x_cord - imageTouchX);
img.setY(y_cord - imageTouchY);
if(img.getX() < 100){
return false;
}
break;
default:
break;
}
return true;
}
Thanks in advance.