Android 提供的 onKey()、OnKeyDown() 和 dispatchKeyEvent() 方法的区别? [英] Difference between onKey(), OnKeyDown() and dispatchKeyEvent() methods provided by Android?

查看:17
本文介绍了Android 提供的 onKey()、OnKeyDown() 和 dispatchKeyEvent() 方法的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 提供的 onKey()、OnKeyDown() 和 dispatchKeyEvent() 方法有什么区别?
我想知道何时何地可以使用这些中的每一个.
请对此有所了解.

What is the difference between onKey(), OnKeyDown() and dispatchKeyEvent() methods provided by Android?
I Would like to know when and where each of these can be used.
Please shed some light into this.

推荐答案

追踪5.1 视图类的来源.看起来 dispatchKeyEvent() 是系统调用的第一个方法.重载它将阻止调用任何和所有关键事件,除非调用基本版本.

Tracing the source code of the 5.1 Source for the View Class. It would seem that dispatchKeyEvent() is the first method called by the system. Overloading it will prevent any and all key events from being called unless the base version is called.

dispatchKeyEvent() 的第一步是尝试将事件传递给 onKeyListener 如果有的话.这是调用 onKey() 的时候.如果 onKey() 实现返回 truedispatchKeyEvent() 将返回那里并且不会调用其他事件.

dispatchKeyEvent()'s first move is to attempt to pass the event to an onKeyListener if there is one. This is when onKey() is called. If the onKey() implementation returns true, dispatchKeyEvent() will return there and other events will not be called.

如果没有onKeyListener或者onKeyListeneronKey()方法返回falsedispatchKeyEvent() 然后将调用 KeyEventdispatch() 方法.然后它将依次调用 KeyEvent.Callback 中的所有方法 界面在您的视图中.这包括 onKeyDown()onKeyUp().

If there is no onKeyListener or the onKeyListener's onKey() method returned false, dispatchKeyEvent() will then call the KeyEvent's dispatch() method. Which will then in turn call all the methods in the KeyEvent.Callback interface on your view. This includes onKeyDown() and onKeyUp().

这篇关于Android 提供的 onKey()、OnKeyDown() 和 dispatchKeyEvent() 方法的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆