Samueljh1
Samueljh1

Reputation: 317

Android setOnEditorActionListener not working

for some reason the setOnEditorActionListener is not working.

Im on the target sdk of 22.

Here is the code inside my onCreate Method:

final EditText pageBox = (EditText) findViewById(R.id.pageBox);

    searchBox.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {

        }
      }
    });

And here is the xml:

<EditText
   android:layout_width="0dp"
   android:layout_height="wrap_content"
   android:id="@+id/searchBox"
   android:singleLine="true"
   android:hint="@string/string_find_player"
   android:layout_gravity="left"
   android:layout_weight="1" />

All Help is greatly appreciated!

Upvotes: 0

Views: 3468

Answers (2)

Aram Sheroyan
Aram Sheroyan

Reputation: 588

What object is searchBox, maybe you have to add listener to pageBox

Upvotes: 0

roarster
roarster

Reputation: 4086

You should try adding android:imeOptions="actionDone" to your xml since you're looking for that code (EditorInfo.IME_ACTION_DONE):

<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/searchBox"
android:singleLine="true"
android:hint="@string/string_find_player"
android:layout_gravity="left"
android:layout_weight="1"
android:imeOptions="actionDone" />

Upvotes: 3

Related Questions