【问题标题】:Why does pressing the Go on the android keyboard send two KeyEvents to onEditActionListener为什么在android键盘上按Go会向onEditorActionListener发送两个键事件
【发布时间】:2019-06-03 04:25:26
【问题描述】:

我只是很好奇为什么在我记录事件时 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 }

我不知道为什么会有第二个事件。

【问题讨论】:

  • 你能和EditText分享xml布局吗?

标签: java android textview android-edittext keyevent


【解决方案1】:

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

【讨论】:

  • 是的,但我只使用了 EditorAction 侦听器 - 模拟器会自动注册 Go 点击 - 我认为您不能将 EditorActionListener 限制为仅一个事件。它似乎只接受发送给它的任何内容。
猜你喜欢
  • 2013-03-12
  • 2014-10-08
  • 1970-01-01
  • 2011-03-06
  • 1970-01-01
  • 1970-01-01
  • 2018-09-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多