onEditorAction()不叫回车键后一直pssed上果冻豆仿真器$ P $仿真器、回车键、果冻、不叫

2023-09-05 01:58:02 作者:风吻过你的脸

我在用最新的果冻豆仿真器的行为存在问题。我有几个 EditTexts 在我的应用程序。一个 OnEditorActionListener 提供了特殊的处理,当用户presses键盘上的回车键。这个工作,直到ICS,但现在对果冻豆的侦听器回调方法 onEditorAction()不再被调用。只有一个新行插入的EditText

I'm having a problem with the behavior of the latest Jelly Bean emulator. I have several EditTexts in my app. An OnEditorActionListener provides special handling when a user presses the ENTER key on the keyboard. This worked up until ICS, but now on Jelly Bean the listener callback method onEditorAction() no longer gets called. Only a new line is inserted into the EditText.

这可以重现这种方式:

EditText testEditText = new EditText(context);
testEditText.setOnEditorActionListener(new OnEditorActionListener() {

    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        Log.d(TAG, "onEditorAction() called");
        return false;
    }
});
addView(testEditText);

这是在果冻豆中的错误?或者在模拟器?或者有行为改变故意?

Is this a bug in Jelly Bean? Or in the emulator? Or has the behavior been changed intentionally?

奇怪的是别人写,该方法被调用,但意外的参数,在一台Nexus 7上运行果冻豆的位置:null KeyEvent的和actionid = 0 onEditorAction()(果冻豆/的Nexus 7)

Curiously someone else writes that the method gets called, but with unexpected parameters, on a Nexus 7 running Jelly Bean here: null keyevent and actionid = 0 in onEditorAction() (Jelly Bean / Nexus 7)

推荐答案

如果别人发现了这个问题:

If someone else finds this question:

我测试过几次,并在果冻豆仿真器监听回调方法onEditorAction()确实不再被调用时,回车键是pssed在虚拟键盘上$ P $。

I've tested this several times and on the Jelly Bean emulator the listener callback method onEditorAction() indeed no longer gets called when the Enter key is pressed on the virtual keyboard.

正如我上面提到的一个可能的解决方案或替代方法是用现有的操作键之一替代Enter键。那些依旧会触发onEditorAction()。我也有指定的输入类型。

As I mentioned above a possible solution or workaround is to replace the Enter key with one of the available action keys. Those still trigger onEditorAction(). I also had to specify the input type.

editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setImeOptions(EditorInfo.IME_ACTION_GO);

<EditText
...
android:imeOptions="actionGo"
android:inputType="text" />