So i want to detect which direction the user moved his finger when touching the screen Right now its working for 3 directions but the "up" movement does not get called.
This is my code:
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
// store the X value when the user's finger was pressed down
downXValue = event.getX();
downYValue = event.getY();
break;
}
case MotionEvent.ACTION_UP: {
// Get the X value when the user released his/her finger
float currentX = event.getX();
float currentY = event.getY();
//check if horizontal or vertical movement was bigger
if (Math.abs(downXValue - currentX) > Math.abs(downYValue)
- currentY) {
Log.e("motionevent", "x");
// going backwards: pushing stuff to the right
if (downXValue < currentX) {
Log.e("motionevent", "right");
}
// going forwards: pushing stuff to the left
if (downXValue > currentX) {
Log.e("motionevent", "left");
}
} else {
Log.e("motionevent", "y");
if (downYValue < currentY) {
Log.e("motionevent", "up");
}
if (downYValue > currentY) {
Log.e("motionevent", "down");
}
}
break;
}
}
return true;
}
Is there a Problem with checking for horizontal or vertical movement? because whenever i do an up movement, right or left gets called. down works fine.