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

查看:908
本文介绍了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()实现返回 true dispatchKeyEvent()将返回那里,其他事件不会被调用。

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 onKeyListener onKey()返回的方法 false dispatchKeyEvent()然后调用 KeyEvent dispatch() 方法。然后,它们将调用 中的所有方法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天全站免登陆