Android setOnEditorActionListener() doesn't fire

You can use TextWatcher.

editText.addTextChangedListener(new TextWatcher() {
    
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }
        
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }
        
    @Override
    public void afterTextChanged(Editable s) {
        if (s.charAt(s.length() - 1) == '\n') {
              Log.d("TAG", "Enter was pressed");
        }
    }
});

Make sure that you have an IME_ACTION set in the layout file:

<EditText
    android:id="@+id/search"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="@string/search_hint"
    android:inputType="text"
    android:imeOptions="actionSend" />

For a full explanation, see http://developer.android.com/guide/topics/ui/controls/text.html.


What worked for me is this,I have added this below line to EditText

android:imeOptions="actionSend"

this line makes keyboard which pops up when clicked on edit text has send button instead of search

in the setOnEditorActionListener you override following method looking for action send

@Override
    public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
        if (actionId == EditorInfo.IME_ACTION_SEND) {
        //implement stuff here
          }
        }

Tags:

Java

Android

Ime