按钮单击以使用鼠标滚动工作setOnGenericMotionListener事件

时间:2016-04-28 08:42:43

标签: java android mouseevent motionevent

爵士     我在按钮键上工作,它显示一些像Eg的值:5如果我将鼠标光标指向按钮,然后在setOnGenericMotionListener事件上使用鼠标滚动Eg:5改变增加和减少值取决于鼠标滚动但现在我想移动鼠标光标点的任何地方都需要使用鼠标滚动事件设置setOnGenericMotionListener事件来处理该特定按钮如何才能执行此事件?

  

活动

using (ZipArchive archive = ZipFile.OpenRead(ZipFilePath))
{
    rootArchiveFolder = archive.Entries.Count();        
}

1 个答案:

答案 0 :(得分:1)

您不应该使用此方法来检测触摸事件。 在View.onGenericmotionEvent描述中:

    /**
     * Implement this method to handle generic motion events.
     * <p>
     * Generic motion events describe joystick movements, mouse hovers, track pad
     * touches, scroll wheel movements and other input events.  The
     * {@link 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.
     * </p><p>
     * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER}
     * are delivered to the view under the pointer.  All other generic motion events are
     * delivered to the focused view.
     * </p>
     * <pre> 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 mouse hover movement...
     *                 return true;
     *             case MotionEvent.ACTION_SCROLL:
     *                 // process the scroll wheel movement...
     *                 return true;
     *         }
     *     }
     *     return super.onGenericMotionEvent(event);
     * }</pre>
     *
     * @param event The generic motion event being processed.
     * @return True if the event was handled, false otherwise.
     */
    public boolean onGenericMotionEvent(MotionEvent event) {
        return false;
    }

您可以在here

找到此方法的一些使用情况

顺便说一下,您应该使用GestureDetector来处理您的手势。