Use "Enter" Key on Softkeyboard Instead of Clicking Button

Use ENTER key on softkeyboard instead of clicking button

You do it by setting a OnKeyListener on your EditText.

Here is a sample from my own code. I have an EditText named addCourseText, which will call the function addCourseFromTextBox when either the enter key or the d-pad is clicked.

addCourseText = (EditText) findViewById(R.id.clEtAddCourse);
addCourseText.setOnKeyListener(new OnKeyListener()
{
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_DOWN)
{
switch (keyCode)
{
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
addCourseFromTextBox();
return true;
default:
break;
}
}
return false;
}
});

Use “ENTER” key on softkeyboard to initiation an Event

Alright, thanks to George Rappel - I was sent in the right direction. I found my solution in the online android source code - took some hunting for that. Below is the code for ENTER - where ENTER is the value 10.

case ENTER:

final EditorInfo editorInfo = getCurrentInputEditorInfo();
final int imeOptionsActionId = InputTypeUtils.getImeOptionsActionIdFromEditorInfo(editorInfo);
if (InputTypeUtils.IME_ACTION_CUSTOM_LABEL == imeOptionsActionId) {
// Enter used as submission
ic.performEditorAction(editorInfo.actionId);
} else if (EditorInfo.IME_ACTION_NONE != imeOptionsActionId) {
// Not quite sure what this is for
ic.performEditorAction(imeOptionsActionId);
} else {
// Enter being used as text
ic.commitText(String.valueOf((char) primaryCode), 1);
}
break;

I also copied the necessary methods from the class InputTypeUtils.java found in the online android repository.

Soft keyboard enter key event handle

The best way possible:

if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
Log.d(TAG, "enter_key_called");
}

Android keyboard change enter key

The solution for me was adding these two lines in the XML of Edittext

android:imeOptions="actionDone"
android:inputType="text"

Thx everyone.

Enter key on softkeyboard not triggering event when pressed

Try adding the following code to your R.id.search_view:

android:imeOptions="actionSearch" 
android:inputType="text"

Use OK key on softkeyboard (numberPassword keyboard) instead of clicking button?

 mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// call some function
return false;
}
});

if you want to change "Done" button title, use:

mEditText.setImeActionLabel("OK", KeyEvent.KEYCODE_ENTER);

When Pressing Enter button on EditText is creating a new line

These 3 flags will solve your issue. Add them to your edit text view.

android:inputType="text"
android:imeOptions="actionNext"
android:maxLines="1"

Android: how to make keyboard enter button say Search and handle its click?

In the layout set your input method options to search.

<EditText
android:imeOptions="actionSearch"
android:inputType="text" />

In the java add the editor action listener.

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
}
});

handle enter key in soft keyboard in custom Layout

When those buttons are pressed, the soft keyboard calls InputConnection.performEditorAction(int action). So when you want to send a GO, NEXT, etc just call that function. If you want to send an enter, just commit a newline.



Related Topics



Leave a reply



Submit