I\'m making an application, in this application I have edit text. I want when user write some text in edit text end then press enter button, I want it call some command. This wh
This is a known bug that makes the Enter
key not be recognized on several devices. A workaround to avoid it and make it work would be the following:
Create a TextView.OnEditorActionListener
like this:
TextView.OnEditorActionListener enterKey = new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
// Do whatever you need
}
return true;
}
};
Assuming your View
is an EditText
, for instance, you'd need to set it this way:
final EditText editor = (EditText) findViewById(R.id.Texto);
editor.setOnEditorActionListener(enterKey);
The final step to go is assigning the following attribute to the EditText
:
android:imeOptions="actionGo"
This basically changes the default behavior of the enter key, setting it to the actionGo
IME option. In your handler simply assign it the listener you've created and this way you'll have the enter key
behavior.