I have an Edittext with imeoptions
asactiongo
. and I triggered my event when pressing soft keyboard enter button.
mModelId.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
// if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
if (actionId == EditorInfo.IME_ACTION_GO) {
id = mModelId.getText().toString();
System.out.println("Model id in Edittext:-"+ id);
Toast.makeText(getActivity(), "You entered "+id, Toast.LENGTH_LONG).show();
System.out.println("Before Call Volley");
callVolley();
handled = true;
}
return handled;
}
});
Everything works fine but when I add actionlabel to enter key the event is not firing. mModelId.setImeActionLabel("Search Model", KeyEvent.KEYCODE_ENTER);
. What may be the problem?
Supply a value for EditorInfo.actionId used when an input method is connected to the text view.
numberEditor.mInputContentType.onEditorActionListener.onEditorAction( this, EditorInfo.IME_NULL, event))
Supply a value for EditorInfo.actionLabel used when an input method is connected to the text view.
Must be a string value, using '\;' to escape characters such as '\n' or '\uxxxx' for a unicode character.
setImeActionLabel
take two parameters and the second int parameter should be one of the those that are in theEditorInfo
class. Such as:You cannot send there any other integer like
KeyEvent.KEYCODE_ENTER
And you have to set both
imeOptions
parameter andsingleLine
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:try this
declare edittext and OnEditorActionListener() like this
and you use imeoptions as actionGo then revome it, i think it override ImeActionLabel once try this and reply
I've checked at Android 2.1 and Android 4.0 versions and your code is working fine.
IME_ACTION_GO
event is reported in case EditText hassingleLine
option specified totrue
. In case it is specified tofalse
actionId
hasIME_NULL
value independently of thesetImeActionLabel
was called or no.In the TextView.onKeyDown method i've found that
IME_NULL
actionId is used whenKEYCODE_ENTER
is detectedPerhaps it is custom keyboard issue. Do you use any? If so try these changes:
instead of
should be