Reputation: 260
I have an android xml layout and i want to specify the focus order of the fields, when user presses next on the keyboard.
Documentation says, that android:nextFocusForward=TARGET_ID should do that trick. But it is ignored on all our testing devices. Some old devices running 2.3 and new Nexus devices running 4.1.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:textCursorDrawable="@null"
android:id="@+id/firstname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:layout_weight="1"
android:singleLine="true"
android:background="#00000000"
android:textColor="#000"
android:nextFocusForward="@+id/lastname"
android:padding="2dp"/>
<EditText
android:textCursorDrawable="@null"
android:id="@+id/lastname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:layout_weight="1"
android:background="#00000000"
android:singleLine="true"
android:textColor="#000"
android:padding="2dp"/>
</LinearLayout>
What am i doing wrong here??? Just can't figure it out. Thanks a lot!
Upvotes: 5
Views: 5208
Reputation: 77
I had an issue where I had text fields in a grid with two columns and several rows defined and arranged using the ConstraintLayout
and Flow
.
android:nextFocusDown="@id/..."
Worked for me in all text fields regardless of the next view being on the right.
Upvotes: 0
Reputation: 604
It's been a long time, but I just had the problem and found the solution. nextFocusForward works when AutoCompleteTextView is overwritten with imeOptions. I have this code in my EditText fields and it works:
android:imeOptions="actionNext"
android:nextFocusForward="@+id/et_xyz"
Upvotes: 1
Reputation: 3048
I had a similar issue within toolbar/actionbar with JetPack. I seems toolbar widget totally ignores the nextFocus properties. I solved it by not using those legacy widgets and using a custom toolbar base on standard widgets.
Upvotes: 0
Reputation: 24068
I tried setting nextFocusDown, nextFocusForward, nextFocusRight, but none of them worked. I got it working by listening for editor action and programmatically setting the focus to the next EditText.
mFirstName.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
mLastName.requestFocus();
return true;
}
});
Upvotes: 1
Reputation: 3939
Try nextFocusDown as well. I don't fully understand the rules, but it seems that the behavior depends on the layout of the EditTexts, and where the cursor position is relative to the next field.
Upvotes: 11