4

I am a beginner in Android. I need to swipe only from left to right and to do not swipe from right to left. For this what I want to do? All the examples are showing both left to right and right to left?

halfer
  • 19,824
  • 17
  • 99
  • 186
RIJO R V
  • 367
  • 3
  • 13
  • What do you want to happen when you swipe ? Maybe you can post some of the examples you found and explain what you want to do differently... – Matthieu Sep 24 '12 at 06:04
  • http://stackoverflow.com/questions/10008053/android-trouble-with-swipe-gesture is an example which i referred. In that example also they are doing both direction swipe. I need only from left to right. – RIJO R V Sep 24 '12 at 06:14

2 Answers2

1

You can Use Drag and Drop You can Study this tutorial this is very nice tutorial

http://www.vogella.com/articles/AndroidDragAndDrop/article.html

aur you can have alook to

http://developer.android.com/guide/topics/ui/drag-drop.html

raghav chopra
  • 827
  • 3
  • 9
  • 25
  • This example is only about the drag and drop. I need to do the swipe operation from left to right. Please help me on that. – RIJO R V Sep 24 '12 at 06:11
1

Take a look at the accepted solution here - Fling gesture detection on grid layout

The solution explains how to implement a simple gesture listener, and record left to right and right to left swipes. The relevant code from the example is in the GestureDetector onFling override method. Basically, if point 1 (e1) minus point 2 (e2) is greater than a set minimum swipe distance, then you know it's right to left. If point 2 (e2) minus point 1 (e1) was greater than the minimum swipe distance then it's left to right.

// right to left swipe
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
    Toast.makeText(SelectFilterActivity.this, "Left Swipe", Toast.LENGTH_SHORT).show();
}  
// left to right swipe
else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
     Toast.makeText(SelectFilterActivity.this, "Right Swipe", Toast.LENGTH_SHORT).show();
}
Community
  • 1
  • 1
Kyle Clegg
  • 38,547
  • 26
  • 130
  • 141