How do I trigger an action when the user has hit enter?

僤鯓⒐⒋嵵緔 提交于 2019-12-01 16:58:14
Entropy1024

I played around a bit with various things and found that the code below works:

myEditText.setOnEditorActionListener(new OnEditorActionListener() {                     
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        // Do some stuff
    }
});

I believe you want is the setOnEditorActionListener() method, dev guide info here on the method.

DrColossos

Add a KeyListener to the textbox that listens key events. Within the key event, listen to the "ENTER" key pressed and perform your action.

You can find something similar here: Android Development: How To Use onKeyUp? and in the docs for UI-Events.

A good example is in the linked SO question. Following this, you should get the desired result.

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