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 b
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.
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.