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.