Thanks works like a charm but you should add a constructor to OnSwipeTouchListener that receives a context because that constructor of GestureDetector is deprecated since API level 3, and instantiate the GestureDetectorin that constructor.
–
Hugo AlvesOct 1 '13 at 9:56

@Jona You'll definitely want to get a good book or other resource on Android fundamentals; otherwise, trying to cobble solutions together from StackOverflow will prove frustrating. A good option is the official Training for Android developers. The section Starting an Activity tells about where you would put setOnTouchListener (typically in onCreate). context is the this pointer (unless you're creating a fragment).
–
Edward BreyJun 20 '14 at 10:14

I don't see easily the modifications in your modified OnSwipeTouchListener. Where is it exactly ?
–
Nicolas ZozolOct 23 '13 at 20:48

1

This should be the accepted answer... Differences are subtle but very important. First, there is no onDown(). Second, the handlers return a boolean to signal whether they consumed the event or not. This is of utmost importance if you need more than just one handler for the same view (which should be the default case, anyway).
–
GáborNov 7 '14 at 23:24

Expanding on Mirek's answer, for the case when you want to use the swipe gestures inside a scroll view. By default the touch listener for the scroll view get disabled and therefore scroll action does not happen. In order to fix this you need to override the dispatchTouchEvent method of the Activity and return the inherited version of this method after you're done with your own listener.

In order to do a few modifications to Mirek's code:
I add a getter for the gestureDetector in the OnSwipeTouchListener.

Needs some minor updates. Variables are mismatched in the onTouch method, and exception class is not imported. Would make more sense to just return false from onFling(), instead of initiating a variable, assigning it a value, doing nothing with it, and just returning it.

One helpful tip that would've saved me some time and I hope may help others: when you use this method, you only want to add the "implements" tag to your OnSwipeTouchListener class. Your Activity and View are not implementing it. They are just taking advantage of your class that already does!

What the difference? We set result = true, only if we have checked that all requrinments (both SWIPE_THRESHOLD and SWIPE_VELOCITY_THRESHOLD are Ok ). This is important if we discard swipe if some of requrinments are not achieved, and we have to do smth in onTouchEvent method of OnSwipeTouchListener!

Then it should be a comment on that answer - otherwise, as other answers are added, we don't know which one you are referring to. An answer should be complete on its own. If another answer is incomplete, it's helpful to improve it with comments.
–
Mike StockdaleMay 22 '14 at 22:04

If you want to display some buttons with actions when an list item is swipe are a lot of libraries on the internet that have this behavior.
I implemented the library that I found on the internet and I am very satisfied. It is very simple to use and very quick. I improved the original library and I added a new click listener for item click. Also I added font awesome library (http://fortawesome.github.io/Font-Awesome/) and now you can simply add a new item title and specify the icon name from font awesome.