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

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

问题描述

onKey()的onkeydown()和dispatchKeyEvent()搭载Android提供的方法之间的区别是什么?
我想知道何时何每种都可以使用。
请一些启发到这一点。

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.

推荐答案

追踪的源头code <一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.1_r2/android/view/View.java">2.1源视图类。这似乎是<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.1_r2/android/view/View.java#View.dispatchKeyEvent%28android.view.KeyEvent%29">dispatchKeyEvent()是由系统调用的第一个方法。重载将prevent任何及所有重要事件被称为除非基础版本被调用。

Tracing the source code of the 2.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()被调用。在这种情况下, 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. In this case, dispatchKeyEvent() will return there and other events will not be called.

如果没有 onKeyListener dispatchKeyEvent()将调用的KeyEvent 的<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.1_r2/android/view/KeyEvent.java#KeyEvent.dispatch%28android.view.KeyEvent.Callback,android.view.KeyEvent.DispatcherState,java.lang.Object%29">dispatch()方法。这将则依次拨打的<一个所有方法href="http://developer.android.com/reference/android/view/KeyEvent.Callback.html">KeyEvent.Callback接口上你的看法。这包括<一个href="http://developer.android.com/reference/android/view/View.html#onKeyDown%28int,%20android.view.KeyEvent%29">onKeyDown()和<一href="http://developer.android.com/reference/android/view/View.html#onKeyUp%28int,%20android.view.KeyEvent%29">onKeyUp().

If there is no onKeyListener 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().

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

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