Google+ How to do[Implement] Swipe in Android[In Eclipse] - CodieeHome
“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”
__

How to do Swipe in Android

Goal:-  Detecting swipe events in Android ?

Explanation:-  Android supports eight gestures and Swipe is one of them which is mostly used in apps. A swipe event generally occurs when you drag your hand on screen from one point to another.Sometimes Swipe is considered same as drag but there is some differences between them-

     1. Swipe is faster than drag.

     2. Drag stops affecting screen when you remove your finger from screen    but in case of swipe it affect the screen even after the finger is removed. 

Without getting much in swipe's intro, i am starting with the actual thing for which you are here. To implement swipe in your app, you don't have to do much coding. Because Android provides you a GestureDetector class which detects all types of gesture. It supports the gestures like onDown(), onLongPress(), onFling() but swipe is handled by onFling(). 

Steps:-  So here is the simple steps of implementing Swipe in your App:-

  1. Implement OnGestureListener() interface.
  2. Now you will see a warning sign in your eclipse, click on that and implement all abstract methods.
  3. Look for  the function named onFling().
  4. onFling() function accept four arguments in which first two are of Motion type and Last two are of float type.
  5. first and second argument represent the first(when you first touch the screen) and last(when you release the screen)  touch events (position, pressure, size, addition of another finger, etc.) respectively.
  6. Last two arguments represents the velocities along X-axis and Y-axis respectively.
  7. You also need to create a object of GestureDetector to get information about the gesture happened.

Program:-



Output:-  I don't think that there is a need of uploading the output of this program.When you run this app there is blank screen because we didn't add any component in layout file. When you swipe the screen then there will be a toast message specifying the type of your swipe.

 *In the toast message Toast.LENGTH_LONG is used so you need to wait for next toast message. 

*If you face any problem in implementing this code ,tell me via comments.

If you need any program or any help in programming then Request Here 

If you want to share more information about topic discussed above or find anything incorrect Please do comments.  

For more Programs Stay Connected..Like us on Facebook.

0 comments:

Post a Comment

 
Top