Android - Handle "Enter" in an EditText
android, android-edittext, textview
Solution
I am wondering if there is a way to handle the user pressing Enter while typing in an EditText, something like the onSubmit HTML event.
Yes.
Also wondering if there is a way to manipulate the virtual keyboard in such a way that the "Done" button is labeled something else (for example "Go") and performs a certain action when clicked (again, like onSubmit).
Also yes.
You will want to look at the `android:imeActionId` and `android:imeOptions` attributes, plus the `setOnEditorActionListener()` method, all on `TextView`.
For changing the text of the "Done" button to a custom string, use:
mEditText.setImeActionLabel("Custom text", KeyEvent.KEYCODE_ENTER);
Problem
I am wondering if there is a way to handle the user pressing Enter while typing in an `EditText`, something like the onSubmit HTML event. Also wondering if there is a way to manipulate the virtual keyboard in such a way that the "Done" button is labeled something else (for example "Go") and performs a certain action when clicked (again, like onSubmit).
Related problems
- restrict edittext to single line
- Android: Can't figure how to use setImeActionLabel
- Implicit "Submit" after hitting Done on the keyboard at the last EditText
- How do I handle ImeOptions' done button click?
- Use Done button on Keyboard in Databinding
- Multi-line EditText with Done action button
- EditText ignores the ImeActionLabel