views:

1238

answers:

1

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.

A: 

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.

Lucas S.
In android address book, in the contact list view, i can 'fling' up/down using TrackBall (not just Toouch Screen). But when I look at the source code of address book, I don't see they implement dispatchTrackBall(), so how did they implement 'flinging' via trackball?Any idea?Thank you.
n179911
It is not necessary to call dispatchTrackBall, you can only implement onTrackBallEvent in the view (in this case the list view). http://developer.android.com/reference/android/view/View.html#onTrackballEvent(android.view.MotionEvent)
Lucas S.