myClass 类型的方法 onKeyPreIme(int, KeyEvent) 必须重写或实现超类型
我正在尝试在应用程序中创建一个锁定屏幕,以便当用户(远程)请求时,手机将使用预设密码锁定自身。
我正在尝试使用 onKeyPreIme 方法,因为我读到 onKeyDown() 和其他相关方法有时会在 android 系统执行默认操作后被消耗(可能很少,但可能)。
我让我的代码扩展 View 而不是 Activity,这让 onKeyPreIme 工作,但此时其他编码都不起作用,因为我需要为此扩展 Activity。 我也尝试实现 KeyEvent.Callback 但这并没有改变任何东西。 我检查了 Eclipse 中的设置,它是基于 java 1.6 开发的,我的 android 插件和我的 Eclipse 一样都是最新的。 我的 eclipse 是 Eclipse IDE for Java Developers,还有 Eclipse IDE for Java EE Developers 和 Eclipse Classic。我想知道其中任何一个会有所不同吗?
我最初是在 Eclipse 中构建这个项目的,所以它不是从其他任何地方导入的,所以我知道这不是问题。
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
//do my work here
return super.onKeyPreIme(keyCode, event);
}
我尝试不覆盖,但当然这不会做任何事情,而且我还得到“The method onKeyPreIme(int, KeyEvent) is undefined for the type Activity” for 'return super.onKeyPreIme"
我不知所措 如果我无法让它工作
,使用 onKeyDown (以及 onKeyUp 和 onKeyLongPress)代替会有什么缺点吗
?如何让OnKeyPreIme正常工作?
I am trying to create a lock screen in an app so that when the user requests it (remotely) the phone will lock itself with a preset password.
I'm trying to use the onKeyPreIme method because I read that onKeyDown() and other related methods sometimes will be consumed AFTER the android system does the default action (rare maybe, but possible).
I made my code extend View instead of Activity and that let onKeyPreIme work, but none of the other coding would work at that point because I needed to extend Activity for that.
I also tried implementing KeyEvent.Callback but that doesn't change anything.
I checked my settings in Eclipse, and it is developing based on java 1.6 and my android plugin is completely up to date as is my Eclipse.
The eclipse I have is Eclipse IDE for Java Developers, and there's also Eclipse IDE for Java EE Developers and Eclipse Classic. I wonder if either of those would be different?
I built this project initially in Eclipse, so it wasn't imported from anywhere else, so I know that's not a problem.
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
//do my work here
return super.onKeyPreIme(keyCode, event);
}
I tried not overriding, but of course that doesn't do anything, and I also get "The method onKeyPreIme(int, KeyEvent) is undefined for the type Activity" for 'return super.onKeyPreIme"
I'm at a loss of what to do to get onKeyPreIme working.
If I can't get it to work, would there be any drawbacks to using onKeyDown (and onKeyUp and onKeyLongPress) instead?.
Anyone have any ideas on how to get the OnKeyPreIme to work properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OnKeyPreIme 是一个 View 函数,因此您必须实现自定义 View 组件并重写其中的函数。
OnKeyPreIme is a View function, so you must implement your custom View component and override the function there.