您的位置:首页 > 其它

setOnKeyListener vs setOnTouchListener

2015-04-03 17:45 344 查看

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
lthe touch listener to attach to this view
这两者的区别在于 setOnKeyListener 是硬键盘的监听者,例如手机键盘或者标准键盘,处理KeyEvent,这种事件不能生成OnClick 相关事件;

setOntouchListener是触摸板和鼠标的监听者,处理MotionEvent, 这种事件可以生成OnClick相关事件,

可以仔细阅读下相关文档分辨两种event。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: