8

I am new to Android. Here, I want to implement Swipe Gesture to navigate between Activities. I have googled it and found different answers in different sites. But I could not get the exact point. By reading all of them I got that we need to implement onTouchEvent() and onFlingEvent().

Are these functions enough to implement the Swipe action? Please specify on How to proceed step wise to implement swipe gesture.

I am sorry if I asked you a very simple question as I have asked this question after a long long try of many code snippets.

Can any one please clear my doubt?

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
G K
  • 2,481
  • 4
  • 29
  • 45
  • possible duplicate of [Android - basic gesture detection](http://stackoverflow.com/questions/937313/android-basic-gesture-detection) – Siddharth Lele Jan 21 '13 at 15:14

2 Answers2

7

onTouchEvent is enough. What you want to do is:

  • Create a VelocityTracker and feed it the touch results from the view.
  • When you get a UP event, check what the velocity was. If its more than some threshold amount in the X direction, that counts as a swipe.
  • Start a new activity when you recognize it.

You'll likely have to play with the threshold a bit, otherwise a sloppy tap could be mistaken for a swipe.

Colin O'Dell
  • 8,386
  • 8
  • 38
  • 75
Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
1

If you want to swipe your view then you should use ViewFlipper You can set a onTouchListener on ViewFlipper. And you can register GestureDetector in onTouchListener. Here is one good example for that Android transitions- slide in and slide out.

BBdev
  • 4,898
  • 2
  • 31
  • 45