开发者

Android - How to use onKeyDown?

开发者 https://www.devze.com 2023-03-26 03:14 出处:网络
I would like to use the onKeyDown event to react to hardware buttons on my phone. So I added the fo开发者_Python百科llowing to my class:

I would like to use the onKeyDown event to react to hardware buttons on my phone. So I added the fo开发者_Python百科llowing to my class:

@Override
public boolean onKeyDown (int keyCode, KeyEvent event)
...

But this gives me the following compiler error:

"The method onKeyDown(int, KeyEvent) of type MyClass must override or implement a supertype method"

Does anyone have an idea of how to fix this? Thanks!


Does your MyClass extend a Activity? It must do so in order for you to get the key events.

More info at

http://developer.android.com/reference/android/app/Activity.html#onKeyDown

0

精彩评论

暂无评论...
验证码 换一张
取 消