NativeActivity的覆盖的onkeydown() [英] NativeActivity override onKeyDown()

查看:298
本文介绍了NativeActivity的覆盖的onkeydown()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有我工作的一个 NativeActivity的子类的问题,我的目标是捕获并处理来自Java code,而不是关键事件
 本土code(这主要是由于因为这个),可惜我看不到日志() present在的onkeydown 方法虽然
的onCreate()日志正在打印,我已经放在本地code日志版画为好。看来,的onkeydown 我的 NativeActivity的的子类是永远不会被调用。

任何想法?

 公共类CNativeActivity扩展NativeActivity的{
        私人最终静态字符串变量=CNativeActivity;        保护无效的onCreate(捆绑savedInstanceState){
            Log.v(TAG的onCreate);
            super.onCreate(savedInstanceState);
        }        @覆盖
        公共布尔的onkeydown(INT键code,KeyEvent的事件){
            Log.v(TAG的onkeydown);
            返回true;
        }
}


解决方案

补充工具KeyEvent.Callback

 公共类@ @活动扩展NativeActivity的实现KeyEvent.Callback {
   公共布尔onKeyMultiple(INT键code,诠释计数,KeyEvent的事件)
}

KeyEvent.Callback覆盖本地AInputEvent调度后虽然发生;所以基本上你必须忽略所有旧dipatching并实施一些新的东西,如果你想获得扩展键,如昆明,√,€,£...

I having problem with a NativeActivity subclass I am working on, my goal would be to catch and handle key events from the Java code instead of native code (this is mainly due because this), unfortunately I can not see the Log() present in the onKeyDown method though the onCreate() log is being printed and the log prints I have placed in the native code are as well. It seems that the onKeyDown of my NativeActivity subclass is never called.

Any idea?

public class CNativeActivity extends NativeActivity{                                                                                                                                                                                                                                                                                                                                
        private final static String TAG = "CNativeActivity";                                                                                                                            

        protected void onCreate(Bundle savedInstanceState) {                                                                                                                                  
            Log.v(TAG, "onCreate");                                                                                                                                                          
            super.onCreate(savedInstanceState);                                                                                                                                              
        }                                                                                                                                                                                    

        @Override                                                                                                                                                                            
        public boolean onKeyDown(int keyCode, KeyEvent event) {                                                                                                                              
            Log.v(TAG, "onKeyDown");                                                                                                                                                          
            return true;                                                                                                                                                                      
        }
}   

解决方案

add implements KeyEvent.Callback

public class @activity@ extends NativeActivity implements KeyEvent.Callback  {
   public boolean onKeyMultiple (int keyCode, int count, KeyEvent event)
}

KeyEvent.Callback overrides happen after the native AInputEvent dispatching though; so basically you'll have to ignore all old dipatching and implement something new if you want to get the extended keys like ÷,√,€,£, …

这篇关于NativeActivity的覆盖的onkeydown()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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