Android
android.view
public class

android.view.GestureDetector

java.lang.Object
android.view.GestureDetector

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). To use this class:

Nested Classes
GestureDetector.OnGestureListener The listener that is used to notify when gestures occur. 
GestureDetector.SimpleOnGestureListener A convenience class to extend when you only want to listen for a subset of all the gestures. 

Summary

Public Constructors

            GestureDetector(GestureDetector.OnGestureListener listener, Handler handler)
Creates a GestureDetector with the supplied listener.
            GestureDetector(GestureDetector.OnGestureListener listener)
Creates a GestureDetector with the supplied listener.

Public Methods

          boolean  isLongpressEnabled()
          boolean  onTouchEvent(MotionEvent ev)
Analyzes the given motion event and if applicable triggers the appropriate callbacks on the GestureDetector.OnGestureListener supplied.
          void  setIsLongpressEnabled(boolean isLongpressEnabled)
Set whether longpress is enabled, if this is enabled when a user presses and holds down you get a longpress event and nothing further.
Methods inherited from class java.lang.Object

Details

Public Constructors

public GestureDetector(GestureDetector.OnGestureListener listener, Handler handler)

Creates a GestureDetector with the supplied listener. This variant of the constructor should be used from a non-UI thread (as it allows specifying the Handler).

Parameters

listener the listener invoked for all the callbacks, this must not be null.
handler the handler to use, this must not be null.

Throws

NullPointerException if either listener or handler is null.

public GestureDetector(GestureDetector.OnGestureListener listener)

Creates a GestureDetector with the supplied listener. You may only use this constructor from a UI thread (this is the usual situation).

Parameters

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

Throws

NullPointerException if listener is null.

See Also

Public Methods

public boolean isLongpressEnabled()

Returns

  • true if longpress is enabled, else false.

public boolean onTouchEvent(MotionEvent ev)

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

Parameters

ev The current motion event.

Returns

public void setIsLongpressEnabled(boolean isLongpressEnabled)

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

isLongpressEnabled whether longpress should be enabled.
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48