I have an Edittext with imeoptions asactiongo. and I triggered my event when pressing soft keyboard enter button.
mModelId.setOnE
setImeActionLabel take two parameters and the second int parameter should be one of the those that are in the EditorInfo class. Such as:
EditorInfo.IME_ACTION_GO
EditorInfo.IME_ACTION_DONE
EditorInfo.IME_ACTION_NEXT
....
You cannot send there any other integer like KeyEvent.KEYCODE_ENTER
And you have to set bothimeOptions parameter and singleLine parameter in XML in order it to work. Example:
Here is the code that I used and it is working:
XML Layout:
And the basic Activity code:
mEditText2.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_GO) {
Toast.makeText(MainActivity.this, "You entered " + v.getText().toString(), Toast.LENGTH_LONG).show();
handled = true;
}
return handled;
}
});
mEditText2.setImeActionLabel("Search Model", EditorInfo.IME_ACTION_GO);