android:nextFocusForward - Set Next Focus to TextView/EditText

How to Set Next Focus to a TextView/EditText

android:nextFocusForward was added in API Level 11

Defines the next view to give focus to when the next focus is FOCUS_FORWARD.
If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed.

1. Add 2 TextViews in your main.xml file.

2. Set the android:id of the first TextView to mySecondFocus, and the second TextView to myFirstFocus.

3. Ensure the minSDKVersion is, 11 or greater.

4. In the main.xml file, in the first TextView, add the code below.

  <TextView
        ...
       android:nextFocusForward = "@+id/myFirstFocus"
  />

5. In the second TextView, add the code below.

  <TextView
        ...
       android:nextFocusForward = "@+id/mySecondFocus"
  />

6. This will make the second TextView displayed on the screen the first focus, and the first TextView the second focus. 

7. Compile and run!

Related Articles:
Resources: