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

后端 未结 2 1449
轮回少年
轮回少年 2021-02-07 01:57

I\'m having a problem with the behavior of the latest Jelly Bean emulator. I have several EditTexts in my app. An OnEditorActionListener provides speci

2条回答
  •  情话喂你
    2021-02-07 02:25

    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.

提交回复
热议问题