If application inherit a View class and override the methods like onTouchEvent(), application can intercept these events generated by the Android framework. But since this is tedious, another approach is all of these views contains the nested interfaces with callbacks. These interfaces are Event Listeners.
The common listener methods are:
onClick() using View.OnClickListener
This is from View.onClickListener. called back on touch down or corresponding action using a jog wheel or track ball etc.
onLongClick() using View.OnLongClickListener
Called by the framework on long touch.
onFocusChange() using View.OnFocusChangeListener
Called back when one view is getting unfocused due to user moving away.
onKey() View.OnKeyListener
Called back when user focused an item and pressed a hardware key.
onTouch() using View.OnTouchListener
When a touch event happens such as press, release, or any movement gesture within the screen
onCreateContextMenu Using View.onCreateContextMenuListener
When a context menu being built.
It is to be noted that some of the callbacks are having Bool return value, while others don't need a return type. The methods which are having BOOL return type assume the listener handled the event if the listener returned back TRUE.
When creating a custom Views, some of the common callback method used for event handling are the below
- onKeyDown(int , KeyEvent)
- onKeyUp
- onTrackballEvent
- onTouchEvent
- onFocusChanged
There are few events also bit more important which are below.
Activity.dispatchTouchEvent(MotionEvent) - This allows view to intercept all events before they are passed to the Window
Activity.onInterceptTouchEvent - This allows ViewGroup to watch the events as they are passed to the child views
ViewParent.requestDisallowInterceptTouchEevnt- This allows to request to disallow the above.
There is a touch mode for Views. For e.g. Buttons are focusable in non touch mode, i.e. user is interacting with trackball or keys. In this mode, in order to make actions of a button, first it needs to be focused. But if touch in touch mode, the widget action is directly fired instead of first reporting any focus events.
Focusable components can be specified in the layout XML file like in same below
references:
http://developer.android.com/guide/topics/ui/ui-events.html
No comments:
Post a Comment