null keyevent and actionid = 0 in onEditorAction() (Jelly Bean / Nexus 7)

后端 未结 6 752
醉梦人生
醉梦人生 2020-12-03 10:18

I have an edit text which functions as a search box in my application. In Jelly Bean on my Nexus 7 when I type something into the text box which I am listening on and hit en

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 10:55

    The action id is set to 0 by default for any enter event.

    From the Android documentation:

    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.

    So the proper way to handle enter key events would be:

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_NULL) {
            // Handle return key here
            return true;
        }
        return false;
    }
    

提交回复
热议问题