dispatchKeyEvent调用方法两次 [英] dispatchKeyEvent calling method twice

查看:1830
本文介绍了dispatchKeyEvent调用方法两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现dispatchKeyEvent在我的活动听的Enter键pressed。
问题是,当我点击进入,它会调用我的方法的两倍?我怎样才能解决这个问题?
谢谢你,有一个愉快的一天!

  @覆盖
公共布尔dispatchKeyEvent(KeyEvent的E){
如果(e.getKey code()== KeyEvent.KEY code_ENTER){              输入();
        返回true;
    }
    返回super.dispatchKeyEvent(E);
};


解决方案

固定它,这样做:
起初,我是做 ACTION_DOWN 但是被触发我的一个老问题。

  @覆盖
公共布尔dispatchKeyEvent(KeyEvent的事件){
    如果(event.getKey code()== KeyEvent.KEY code_ENTER){
        如果(event.getAction()== KeyEvent.ACTION_UP){         输入();            返回true;
    }}
    返回super.dispatchKeyEvent(事件);
};

I've implemented dispatchKeyEvent in my activity to listen to the Enter key being pressed. The problem is that when i click enter,it calls my method twice ? How can i fix this ? Thanks,have a nice day !

@Override
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.KEYCODE_ENTER) {

              enter();
        return true;
    }
    return super.dispatchKeyEvent(e);
};

解决方案

Fixed it,done this : At first i was doing ACTION_DOWN but that was triggering an older problem of mine.

 @Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
        if (event.getAction() == KeyEvent.ACTION_UP){

         enter();

            return true;
    }}
    return super.dispatchKeyEvent(event);
};

这篇关于dispatchKeyEvent调用方法两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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