Android – Need help with Android TrackBall Event


I have 2 questions about android TrackBall Event. I appreciate if you can help me with them:

  1. Can I detect the speed of TrackBall event? like in Fling, I can detect a 'big' fling vs a 'small' fling. Can I fling via the track ball?

  2. Why TrackBall Event always follow by Key left/right events? To me, they seem duplicate.

For example, I put debug statement in both dispatchTrackballEvent() and dispatchKeyEvent(), and i switch to 'track ball' mode in emulator. When I move my mouse around, I always see dispatchTrackballEventevent with dispatchKeyEvent.

Thank you for any help.

Best Solution

Answers to your doubts:

  1. TrackBall events in android send you a MotionEvent object (docs), from that object you can read historical info that let's you make a delta of movement, that way you can know with which intensity the ball was rolled.

  2. That is caused because you are not telling the system that you have consumed the event in your onTrackBallEvent handler (docs), if you don't return true the event is then raised as a d-pad key event.