Moving to the next EditText in android

If you want to focus next EditText on enter pressed you can use those options at XML code to focus next EditText:

Option 1:

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:imeOptions="actionNext"
    android:singleLine="true"/>

Option 2:

<EditText
    android:id="@+id/et1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:nextFocusForward="@+id/et2"/>

<EditText
    android:id="@+id/et2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"/>

You need to validate user input to meet your expectations. If that is met, then only call et2.requestFocus()


It might be very late but I have a solution which is much easier to apply. Just add this code to the edittext field in the layout.xml file. Add this to edittext which you want to show a next button instead of a done button. So it will point to the next Edittext field.

android:imeOptions="actionNext"

You can check the key pressed for 1st EditText and if it was "Enter" key,then move focus to next EditText.

This may help you: KeyCode_Enter to next edittext

Tags:

Android