Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

If (in Android) I have an EditText box, how can I trigger an event when the user has finished entering data and hits return/Next?

I have tried using the code below but it seems to have no effect. I also get an 'The method onEditorAction(EditText, int, KeyEvent) from the type new extView.OnEditorActionListener(){} is never used locally' error.

myEditText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
            public boolean onEditorAction(EditText v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_NEXT)
                {
like image 639
Entropy1024 Avatar asked Nov 17 '10 21:11

Entropy1024


People also ask

How do you trigger a function on Enter?

To trigger a click button on ENTER key, We can use any of the keyup(), keydown() and keypress() events of jQuery. keyup(): This event occurs when a keyboard key is released. The method either triggers the keyup event, or to run a function when a keyup event occurs.

How do you trigger button on Enter key react?

To submit a form using the Enter key in React: Add a button element with type set to submit . Add an onSubmit prop that points to a submit handler function. Every time the user presses Enter, the handle submit function will be invoked.

How do you trigger event on enter react?

The onKeyPress event is fired when a user presses the key on a keyboard, so that by using this we can trigger the button click by pressing a Enter key. The keyCode for the Enter key is 13.

Does enter trigger onclick?

By pressing 'Enter' on focused <input type="text"> you trigger 'click' event on the first positioned element: <button> or <input type="submit"> . If you press 'Enter' in <textarea> , you just make a new text line.


2 Answers

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
    }
});
like image 193
Entropy1024 Avatar answered Nov 08 '22 12:11

Entropy1024


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

like image 40
Bryan Denny Avatar answered Nov 08 '22 13:11

Bryan Denny