user1126515
user1126515

Reputation: 1163

"Next" key on soft keyboard does not display

Well this is making me a bit crazy.

I've got 2 Edit Text fields and a button. I want the soft keyboard to display when the 1st Edit Text gets focus. I want the soft keyboard to show the "Next" key so when its pressed the cursor jumps to the second Edit Text field.

When the second Edit Text field gets the cursor, I still want the soft keyboard to show "Next". Pressing "Next" now will dismiss the soft keyboard and make focus go to the button.

Here's my code:

EditText editText1 = (EditText) findViewById(R.id.some_text_field);
EditText editText2 = (EditText) findViewById(R.id.some_other_text_field);

editText1.setInputType(EditorInfo.some constant);
editText1.setFocusable(true);
editText1.setFocusableInTouchMode(true); 

if (editText1.requestFocus()){
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

    if (imm != null){
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
    }               
}

editText1.setImeOptions(EditorInfo.IME_ACTION_NEXT);
editText1.setNextFocusDownId(R.id.some_other_text_field);
editText2.setInputType(EditorInfo.some other constant);
editText2.setFocusable(true);
editText2.setFocusableInTouchMode(true);
editText2.setImeOptions(EditorInfo.IME_ACTION_DONE);

Seems pretty straightforward.

Thing is, the first time this runs (after app install) editText1 gets focus and the soft keyboard displays BUT there is no "Next" key - instead it displays "Done". Pressing "Done" moves you to editText2 (like you want) and changes "Done" to "Next. Hitting "Next" now leaves focus on editText2 and dismisses the soft keyboard.

IF you touch editText1 now, the soft keyboard displays and the "Next" key appears like its supposed to.

What can I do to get the proper behavior (editText1 gets focus, "Next" displays) to happen on the first run of this Activity?

I thought editText1.setImeOptions(EditorInfo.IME_ACTION_NEXT); was supposed to force the "Next" key to display. What am i missing?

Upvotes: 0

Views: 1743

Answers (2)

user2776223
user2776223

Reputation:

to navigate the focus to the next edit field add

android:imeOptions="flagNavigateNext"

and for dismissing the softkey with done click add

android:imeOptions="actionDone"

Upvotes: 0

Chamu
Chamu

Reputation: 194

Have you tried doing the same from layout file. I did it in layout file and is working. Following is my working code for login edittexts

  <EditText
    android:id="@+id/et_sign_in_with_email_email"
    style="@style/SignInEditText"
    android:layout_below="@id/rl_titlebar_signin"
    android:layout_marginTop="16dp"
    android:hint="@string/hint_email"
    android:imeOptions="actionNext"
    android:inputType="textEmailAddress" >
</EditText>

<EditText
    android:id="@+id/et_sign_in_with_email_pwd"
    style="@style/SignInEditText"
    android:layout_below="@+id/et_sign_in_with_email_email"
    android:layout_marginTop="20dp"
    android:hint="@string/hint_pwd"
    android:imeOptions="actionDone"
    android:inputType="textPassword" />

Upvotes: 3

Related Questions