android:nextFocusLeft - Set the Next Focus Left to a TextView/EditText

How to Set Next Focus Left to a TextView/EditText

android:nextFocusLeft was added in API Level 1

Defines the next view to give focus to when the next focus is FOCUS_LEFT.
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 myTextView1, and the second TextView to myTextView2.

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

  <TextView
        ...
       android:nextFocusLeft = "@+id/myTextView2"
  />

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

  <TextView
        ...
       android:nextFocusLeft = "@+id/myTextView1"
  />

5. Compile and run!

Related Articles:
Resources: