OnEditorActionListener not working

I just want to catch an event when the user presses enter on editText.

I did not receive a Toast message, not "Enter pressed", not "Some key pressed!". or.

What am 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; } }); 

ED i T:

Well, it works on Android 2.3.3 and does not work on 4.1.2 Any ideas how I can make this work on any Android device?

+8
android android-edittext
Apr 09 '13 at 12:26
source share
4 answers

Try installing EditText in single line mode.

 editText.setSingleLine(); 

or in your xml layout file:

 android:singleLine="true" 

UPDATE

android:singleLine="true" deprecated. From now on, use android:maxLines="1" with android:inputType="text" to achieve this behavior

and

 editText.setMaxLines(1); editText.setInputType(InputType.TYPE_CLASS_TEXT); 

for software setup.

+25
Sep 23 '13 at 7:03
source share
 myEditText.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) { Toast.makeText(getApplicationContext(), "some key pressed", Toast.LENGTH_LONG) .show(); return false; } }); 

This code displays me pressing a key when I press an enter key after entering something in my editor. But I do not know what is the problem in your code.

+1
Apr 09 '13 at
source share

use android:imeOptions="actionGo" in xml. actionDone no longer responds to onEditorAction .

+1
Jan 11 '16 at 5:52
source share

The problem for me was that I set the android:inputType="textMultiline" XML android:inputType="textMultiline" . When I removed the textMultiline parameter, textMultiline started working.

+1
Jan 20 '16 at 12:01
source share



All Articles