NativeActivity override onKeyDown()

一世执手 提交于 2019-12-25 04:28:06

问题


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;                                                                                                                                                                      
        }
}   

回答1:


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 ÷,√,€,£, …



来源:https://stackoverflow.com/questions/28504926/nativeactivity-override-onkeydown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!