Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnEditorActionListener not working

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?

like image 427
Adam Varhegyi Avatar asked Apr 09 '13 12:04

Adam Varhegyi


4 Answers

android:inputType="text" and android:imeOptions="actionGo" do the wonder.

like image 70
Atul Chaturvedi Avatar answered Nov 11 '22 02:11

Atul Chaturvedi


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

like image 33
Samvid Mistry Avatar answered Nov 11 '22 01:11

Samvid Mistry


Please try to set the EditText in single line mode.

editText.setSingleLine();

or in your xml layout file:

android:singleLine="true"

UPDATE

android:singleLine="true" is deprecated. From now on, use android:maxLines="1" with android:inputType="text" for achieving this behaviour

OR

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

for setting programmatically.

like image 29
Yang Peiyong Avatar answered Nov 11 '22 00:11

Yang Peiyong


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

like image 2
Gerrerth Avatar answered Nov 11 '22 01:11

Gerrerth