Android handles scroll wheel events

Source: Internet
Author: User


Android does not process the scroll wheel event as follows:

1) public boolean onKeyDown (int keyCode, KeyEvent event)

2) public boolean dispatchKeyEvent (KeyEvent event)

3) public boolean onTouchEvent (MotionEvent event)


But the following functions:

Publicboolean onGenericMotionEvent (MotionEvent event );


All views and activities can rewrite this function to handle scroll wheel events by themselves,

The following code:


/*** Implement this method to handle generic motion events. * This method is used to handle general motionevents. * General motion events descriptions, joystick actions, mouse honvers, and scroll wheel ** @ param event The generic motion event being processed. * @ return True if the event was handled, false otherwise. * // @ Overridepublic boolean onGenericMotionEvent (MotionEvent event) {// The input source is a pointing device associated with a display. // The input source is a display pointer device, such as mouse poin. Ting device (mouse pointer), stylus pointing device (tip pen device) if (0! = (Event. getSource () & InputDevice. SOURCE_CLASS_POINTER) {switch (event. getAction () {// process the scroll wheel movement... processing wheel event case MotionEvent. ACTION_SCROLL: // obtain the scroll direction on the vertical coordinate, that is, roll the scroll wheel down if (event. getAxisValue (MotionEvent. AXIS_VSCROLL) <0.0f) {Log. I ("fortest: onGenericMotionEvent", "down");} // obtain the scroll direction on the vertical coordinate, that is, roll the wheel up else {Log. I ("fortest: onGenericMotionEvent", "up") ;}return true ;}} return super. onGenericMotionEvent (event );}


For more information, see jiese1990.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.