Handle "enter" Key On Jelly Bean
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 what i
Solution 1:
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.OnEditorActionListenerenterKey=newTextView.OnEditorActionListener() {
publicbooleanonEditorAction(TextView view, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
// Do whatever you need
}
returntrue;
}
};
Assuming your View
is an EditText
, for instance, you'd need to set it this way:
finalEditTexteditor= (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.
Post a Comment for "Handle "enter" Key On Jelly Bean"