Skip to content

Most visited

Recently visited

navigation

GestureDetectorCompat

public final class GestureDetectorCompat
extends Object

java.lang.Object
   ↳ android.support.v4.view.GestureDetectorCompat


Detects various gestures and events using the supplied MotionEvents. The GestureDetector.OnGestureListener callback will notify users when a particular motion event has occurred. This class should only be used with MotionEvents reported via touch (don't use for trackball events).

This compatibility implementation of the framework's GestureDetector guarantees the newer focal point scrolling behavior from Jellybean MR1 on all platform versions.

To use this class:

Summary

Public constructors

GestureDetectorCompat(Context context, GestureDetector.OnGestureListener listener)

Creates a GestureDetectorCompat with the supplied listener.

GestureDetectorCompat(Context context, GestureDetector.OnGestureListener listener, Handler handler)

Creates a GestureDetectorCompat with the supplied listener.

Public methods

boolean isLongpressEnabled()
boolean onTouchEvent(MotionEvent event)

Analyzes the given motion event and if applicable triggers the appropriate callbacks on the GestureDetector.OnGestureListener supplied.

void setIsLongpressEnabled(boolean enabled)

Set whether longpress is enabled, if this is enabled when a user presses and holds down you get a longpress event and nothing further.

void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener listener)

Sets the listener which will be called for double-tap and related gestures.

Inherited methods

From class java.lang.Object

Public constructors

GestureDetectorCompat

added in version 22.0.0
GestureDetectorCompat (Context context, 
                GestureDetector.OnGestureListener listener)

Creates a GestureDetectorCompat with the supplied listener. As usual, you may only use this constructor from a UI thread.

Parameters
context Context: the application's context

listener GestureDetector.OnGestureListener: the listener invoked for all the callbacks, this must not be null.

See also:

GestureDetectorCompat

added in version 22.0.0
GestureDetectorCompat (Context context, 
                GestureDetector.OnGestureListener listener, 
                Handler handler)

Creates a GestureDetectorCompat with the supplied listener. As usual, you may only use this constructor from a UI thread.

Parameters
context Context: the application's context

listener GestureDetector.OnGestureListener: the listener invoked for all the callbacks, this must not be null.

handler Handler: the handler that will be used for posting deferred messages

See also:

Public methods

isLongpressEnabled

added in version 22.0.0
boolean isLongpressEnabled ()

Returns
boolean true if longpress is enabled, else false.

onTouchEvent

added in version 22.0.0
boolean onTouchEvent (MotionEvent event)

Analyzes the given motion event and if applicable triggers the appropriate callbacks on the GestureDetector.OnGestureListener supplied.

Parameters
event MotionEvent: The current motion event.

Returns
boolean true if the GestureDetector.OnGestureListener consumed the event, else false.

setIsLongpressEnabled

added in version 22.0.0
void setIsLongpressEnabled (boolean enabled)

Set whether longpress is enabled, if this is enabled when a user presses and holds down you get a longpress event and nothing further. If it's disabled the user can press and hold down and then later moved their finger and you will get scroll events. By default longpress is enabled.

Parameters
enabled boolean: whether longpress should be enabled.

setOnDoubleTapListener

added in version 22.0.0
void setOnDoubleTapListener (GestureDetector.OnDoubleTapListener listener)

Sets the listener which will be called for double-tap and related gestures.

Parameters
listener GestureDetector.OnDoubleTapListener: the listener invoked for all the callbacks, or null to stop listening for double-tap gestures.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)