I have the following code:
final float len = getResources().getDisplayMetrics().densityDpi/6;
linear1.setOnTouchListener(new View.OnTouchListener() {
float initX;
float initY;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
initX = event.getX();
initY = event.getY();
break;
case MotionEvent.ACTION_UP:
initX -= event.getX();
initY -= event.getY();
if (initY > len) {
//Logic For Swipe Right
} else if(initY < -len) {
//Logic For Swipe Left
}
break;
}
return false;
}
});
I am trying to make it so that it doesn't perform the logic to "swipe right" when I swipe down and so that it doesn't perform the logic to "swipe left" when I swipe up. I only want right and left detection for the "swipe right" logic and "swipe left" logic, respectively. Right now, when I swipe up it is also doing the "swipe right" logic and when I swipe down it is doing the "swipe left" logic.
Any help on how I would alter this code to avoid that? Maybe even have a separate section to add logic for "swipe up" and "swipe down" separately?