Event Handlers

If you're building a custom component from View, then you'll be able to define several callback methods used as default event handlers. In the document on Building Custom Components, you'll learn see some of the common callbacks used for event handling, including:

• onKevDown(int, KevEvent) - Called when a new key event occurs.

• onKevUp(int, KevEvent) - Called when a key up event occurs.

• onTrackballEvent(MotionEvent) - Called when a trackball motion event occurs.

• onTouchEvent(MotionEvent) - Called when a touch screen motion event occurs.

• onFocusChanged(boolean, int. Rect) - Called when the view gains or loses focus.

There are some other methods that you should be awere of, which are not part of the View class, but can directly impact the way you're able to handle events. So, when managing more complex events inside a layout, consider these other methods:

• Activitv.dispatchTouchEvent(MotionEvent) - This allows your Activity to intercept all touch events before they are dispatched to the window.

• viewGroup.oninterceptTouchEvent(MotionEvent) - This allows a ViewGroup to watch events as they are dispatched to child Views.

• ViewParent.requestDisallowlnterceptTouchEvent(boolean) - Call this upon a parent View to indicate that it should not intercept touch events with onlnterceptTouchEvent(MotionEvent).

0 0

Post a comment