为什么在Android键盘上按Go键会向onEditActionListener发送两个KeyEvent

时间:2019-06-03 04:25:26

标签: java android textview android-edittext keyevent

我只是很好奇为什么记录事件时onEditActionListener会显示两个KeyEvent。

    pageNumET.setOnEditorActionListener(new TextView.OnEditorActionListener(){
        @Override
        public boolean onEditorAction(TextView t, int actionId, KeyEvent event){
            if(!(event == null)){
                Log.e("ACTIONID", actionId+"");
                Log.e("ACTIONEVENT", event+"");
                if(event.getAction() == KeyEvent.ACTION_DOWN){
                    infoText.setText("IT WORKED");

                    return true;
                }
            }

            return false;
        }
    }
);

那是代码,它工作正常。 然后,当我在模拟器中按Go时。

已记录:

E/ACTIONID: 66
E/ACTIONEVENT: null
E/ACTIONID: 0
E/ACTIONEVENT: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_ENTER, scanCode=0, metaState=0, flags=0x16, repeatCount=0, eventTime=427524, downTime=427524, deviceId=-1, source=0x0 }

我不知道为什么还有第二场比赛。

1 个答案:

答案 0 :(得分:0)

如果只想要一个事件,则应使用keyup。参见this