I have an EditText
view in android. On this I want to detect swipe left or right. I am able to get it on an empty space using the code below. But this does not work when I swipe on an EditText
. How do I do that? Please let me know If I am doing something wrong. Thank you.
Code Used:
switch (touchevent.getAction()) { case MotionEvent.ACTION_DOWN: { oldTouchValue = touchevent.getX(); break; } case MotionEvent.ACTION_UP: { float currentX = touchevent.getX(); if (oldTouchValue < currentX) { // swiped left } if (oldTouchValue > currentX ) { swiped right } break; } }
Tap General settings. Find Mail swipe actions and tap it. Tap Change next to either Right swipe or Left swipe. From there, you can adjust what that directional swipe does.
Under Full screen gestures, tap the More Options button below the Swipe gestures option. Tap on Swipe from bottom or Swipe from sides and bottom, depending on your preference. Tap on the slider at the bottom of the screen to customize the Back gesture sensitivity.
Simplest left to right swipe detector:
In your activity class add following attributes:
private float x1,x2; static final int MIN_DISTANCE = 150;
and override onTouchEvent()
method:
@Override public boolean onTouchEvent(MotionEvent event) { switch(event.getAction()) { case MotionEvent.ACTION_DOWN: x1 = event.getX(); break; case MotionEvent.ACTION_UP: x2 = event.getX(); float deltaX = x2 - x1; if (Math.abs(deltaX) > MIN_DISTANCE) { Toast.makeText(this, "left2right swipe", Toast.LENGTH_SHORT).show (); } else { // consider as something else - a screen tap for example } break; } return super.onTouchEvent(event); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With