首页 > 代码库 > 事件回调
事件回调
Listener是一个接口
An event listener is an interface in the View
class that contains a single callback method. These methods will be called by the Android framework when the View to which the listener has been registered is triggered by user interaction with the item in the UI.
1.View里面有接口的声明,以及接口的定义(接口里面有方法)。
2.为View设置监听器(特定已经实现的接口)。
public class View implements Drawable.Callback, KeyEvent.Callback, AccessibilityEventSource {
private OnKeyListener mOnKeyListener;
public interface OnKeyListener {
/**
* Called when a key is dispatched to a view. This allows listeners to
* get a chance to respond before the target view.
*
* @param v The view the key has been dispatched to.
* @param keyCode The code for the physical key that was pressed
* @param event The KeyEvent object containing full information about
* the event.
* @return True if the listener has consumed the event, false otherwise.
*/
boolean onKey(View v, int keyCode, KeyEvent event);
}
public void setOnKeyListener(OnKeyListener l) {
mOnKeyListener = l;
}