public void setOnKeyListener(View.OnKeyListener l)
Added in
API level 1
Register a callback to be invoked when a hardware key is pressed in this view. Key presses in software input methods will generally not trigger the methods of this listener.
Parameters
the key listener to attach to this view
public void setOnTouchListener(View.OnTouchListener l)
Added in
API level 1
Register a callback to be invoked when a touch event is sent to this view.
Parameters
l | the touch listener to attach to this view |
---|
这两者的区别在于 setOnKeyListener 是硬键盘的监听者,例如手机键盘或者标准键盘,处理KeyEvent,这种事件不能生成OnClick 相关事件;
setOntouchListener是触摸板和鼠标的监听者,处理MotionEvent, 这种事件可以生成OnClick相关事件,
可以仔细阅读下相关文档分辨两种event。