I simply want to catch the event when the user press enter on an editText.
I did not get the Toast message, not the "Enter pressed" and not the "Some key pressed!" either.
What m i doing wrong?
myEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Toast.makeText(getApplicationContext(), "Some key pressed!", Toast.LENGTH_LONG).show();
if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
Toast.makeText(getApplicationContext(), "Enter pressed", Toast.LENGTH_LONG).show();
return true;
}
return false;
}
});
E D I T :
Well it is working on Android 2.3.3 and not working on 4.1.2 Any ideas how can i make this work on any android device?
android:inputType="text"
and android:imeOptions="actionGo"
do the wonder.
use android:imeOptions="actionGo"
in xml. actionDone
no longer responds to onEditorAction
.
Please try to set the EditText
in single line mode.
editText.setSingleLine();
or in your xml layout file:
android:singleLine="true"
UPDATE
is deprecated. From now on, use android:singleLine="true"
android:maxLines="1"
with android:inputType="text"
for achieving this behaviour
OR
editText.setMaxLines(1);
editText.setInputType(InputType.TYPE_CLASS_TEXT);
for setting programmatically.
The problem for me was that I had set in XML android:inputType="textMultiline"
. When I removed textMultiline
option, the EditorListener
started working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With