Android
EditText
Soft Keyboard
User Interface
App Development

Move to another EditText when Soft Keyboard Next is clicked on Android

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

On Android, the soft keyboard can show a Next action that moves input focus from one field to the next. This makes forms feel much smoother than forcing users to tap each EditText manually. The implementation is usually straightforward, but it works best when the XML IME options, focus order, and last-field behavior are all configured together.

Use the Right IME Action in XML

The keyboard action button is controlled by android:imeOptions. For fields in the middle of a form, use actionNext.

xml
1<EditText
2    android:id="@+id/firstName"
3    android:layout_width="match_parent"
4    android:layout_height="wrap_content"
5    android:hint="First name"
6    android:inputType="textPersonName"
7    android:imeOptions="actionNext"
8    android:nextFocusForward="@id/lastName" />
9
10<EditText
11    android:id="@+id/lastName"
12    android:layout_width="match_parent"
13    android:layout_height="wrap_content"
14    android:hint="Last name"
15    android:inputType="textPersonName"
16    android:imeOptions="actionDone" />

This does two useful things:

  • it asks the IME to show a Next action for the first field
  • it defines the focus target for the next move

For simple forms, this alone is often enough.

Handle the Action Explicitly in Code When Needed

If you want more control, such as validation before moving focus, attach an editor-action listener.

kotlin
1firstName.setOnEditorActionListener { _, actionId, _ ->
2    if (actionId == EditorInfo.IME_ACTION_NEXT) {
3        lastName.requestFocus()
4        true
5    } else {
6        false
7    }
8}

This is useful when the next step is conditional. For example, you may want to keep focus in the current field until the text is non-empty or matches a format.

A Small Form Example in Kotlin

Here is a minimal activity setup that wires the behavior clearly:

kotlin
1import android.os.Bundle
2import android.view.inputmethod.EditorInfo
3import android.widget.EditText
4import androidx.appcompat.app.AppCompatActivity
5
6class MainActivity : AppCompatActivity() {
7    override fun onCreate(savedInstanceState: Bundle?) {
8        super.onCreate(savedInstanceState)
9        setContentView(R.layout.activity_main)
10
11        val firstName = findViewById<EditText>(R.id.firstName)
12        val lastName = findViewById<EditText>(R.id.lastName)
13
14        firstName.setOnEditorActionListener { _, actionId, _ ->
15            if (actionId == EditorInfo.IME_ACTION_NEXT) {
16                lastName.requestFocus()
17                true
18            } else {
19                false
20            }
21        }
22
23        lastName.setOnEditorActionListener { _, actionId, _ ->
24            if (actionId == EditorInfo.IME_ACTION_DONE) {
25                lastName.clearFocus()
26                true
27            } else {
28                false
29            }
30        }
31    }
32}

Notice that the last field uses Done, not Next. That makes the keyboard behavior match the structure of the form.

Prefer Declarative Focus Order for Simple Forms

If the form is linear and has no special rules, XML focus attributes are often cleaner than listener-heavy code. Android can move focus correctly when the next field is already known.

Useful attributes include:

  • 'android:nextFocusForward'
  • 'android:nextFocusDown'
  • 'android:nextFocusRight'

The more complex the validation or conditional branching becomes, the more likely you are to need explicit listener code instead.

Make the Last Field Behave Differently

A common UX mistake is setting every field to actionNext, including the final one. The last field should usually use actionDone, actionGo, or actionSend depending on what the form is supposed to do.

That gives users a clear sense of progress:

  • middle fields move them forward
  • the final field finishes or submits

This small distinction makes forms feel more deliberate.

Validation and Error Handling

If the current field is invalid, do not blindly advance focus. Keep the cursor in the field and show an error instead.

kotlin
1email.setOnEditorActionListener { _, actionId, _ ->
2    if (actionId == EditorInfo.IME_ACTION_NEXT) {
3        if (email.text.isNullOrBlank()) {
4            email.error = "Email is required"
5            false
6        } else {
7            password.requestFocus()
8            true
9        }
10    } else {
11        false
12    }
13}

That keeps the keyboard flow useful without turning it into a way to skip broken input.

Common Pitfalls

One common mistake is setting imeOptions="actionNext" but never defining a reasonable focus path. The keyboard button appears, but focus movement feels inconsistent.

Another mistake is handling IME_ACTION_NEXT in code while also returning false after moving focus. That can lead to duplicate or odd IME behavior because the event was not fully consumed.

Developers also sometimes forget that the last field should not behave like the middle fields. Using actionDone or another final action is usually the right UX.

Finally, if a form uses custom views or nonstandard focus handling, rely less on XML shortcuts and more on explicit requestFocus() logic so the behavior stays predictable.

Summary

  • Use android:imeOptions="actionNext" on intermediate fields.
  • Define a clear focus path with XML focus attributes or explicit requestFocus() calls.
  • Handle editor actions in code when validation or conditional navigation is needed.
  • Use actionDone or another final action on the last field.
  • Keep invalid input focused in place instead of advancing automatically.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.