onEditorAction() is not called after Enter key has been pressed on Jelly Bean emulator

馋奶兔 提交于 2019-12-03 05:38:07

If someone else finds this question:

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.

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" />
android developer

Here's what I did, which should cover all types of the Enter being pressed:

override fun onEditorAction(v: TextView?, actionId: Int, event: KeyEvent?): Boolean {
    if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_NULL)
        ... // Enter pressed

In XML I added only android:imeOptions="actionGo"

The reason, according to the docs:

https://developer.android.com/reference/android/widget/TextView.OnEditorActionListener.html#onEditorAction(android.widget.TextView,%20int,%20android.view.KeyEvent)

actionId int: Identifier of the action. This will be either the identifier you supplied, or EditorInfo#IME_NULL if being called due to the enter key being pressed.

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