Dela via


View.OnGenericMotionEvent(MotionEvent) Method

Definition

Implement this method to handle generic motion events.

[Android.Runtime.Register("onGenericMotionEvent", "(Landroid/view/MotionEvent;)Z", "GetOnGenericMotionEvent_Landroid_view_MotionEvent_Handler")]
public virtual bool OnGenericMotionEvent (Android.Views.MotionEvent? e);
[<Android.Runtime.Register("onGenericMotionEvent", "(Landroid/view/MotionEvent;)Z", "GetOnGenericMotionEvent_Landroid_view_MotionEvent_Handler")>]
abstract member OnGenericMotionEvent : Android.Views.MotionEvent -> bool
override this.OnGenericMotionEvent : Android.Views.MotionEvent -> bool

Parameters

e
MotionEvent

The generic motion event being processed.

Returns

True if the event was handled, false otherwise.

Attributes

Remarks

Implement this method to handle generic motion events.

Generic motion events describe joystick movements, hover events from mouse or stylus devices, trackpad touches, scroll wheel movements and other motion events not handled by #onTouchEvent(MotionEvent) or #onTrackballEvent(MotionEvent). The MotionEvent#getSource() source of the motion event specifies the class of input that was received. Implementations of this method must examine the bits in the source before processing the event. The following code example shows how this is done.

Generic motion events with source class InputDevice#SOURCE_CLASS_POINTER are delivered to the view under the pointer. All other generic motion events are delivered to the focused view.

public boolean onGenericMotionEvent(MotionEvent event) {
                if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) {
                    if (event.getAction() == MotionEvent.ACTION_MOVE) {
                        // process the joystick movement...
                        return true;
                    }
                }
                if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
                    switch (event.getAction()) {
                        case MotionEvent.ACTION_HOVER_MOVE:
                            // process the hover movement...
                            return true;
                        case MotionEvent.ACTION_SCROLL:
                            // process the scroll wheel movement...
                            return true;
                    }
                }
                return super.onGenericMotionEvent(event);
            }

Java documentation for android.view.View.onGenericMotionEvent(android.view.MotionEvent).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to