Nemo
Nemo

Reputation: 1079

Enter Button on Soft KeyBoard - Android

Im using a a Single Line Edit Text , so when i click on Edit text box, im getting "Go" in place of Enter button. But i want Enter key in place of "Go" key . How can i do this .. Please some one can give solution for this ?

Upvotes: 0

Views: 1977

Answers (2)

DimWorks
DimWorks

Reputation: 1

    EditText editText = findViewById(R.id.editText); // Your EditText

    Button button = findViewById(R.id.button); // Your Button

    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    editText.setRawInputType(InputType.TYPE_CLASS_TEXT);

    editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                button.performClick(); // Imitation of pressing the button

                // Hide the keyboard after pressing
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

                return true;
            }
            return false;
        }
    });

Upvotes: 0

Paresh Mayani
Paresh Mayani

Reputation: 128428

I am not sure but you can try android:imeOptions="actionDone", in short you need to try android:imeOptions attribute.

Upvotes: 1

Related Questions