Paul F
Paul F

Reputation: 49

NextFocusRight doesn't focus on the right, but down

I'm work on an app with multiple edittext. When an edittext take the whole width, the nextfocusdown is working properly. But when there is two edittext at the same height (each edittext takes half of the width), I want to give the focus from the left one to the right one. But when i write nextFocusRight="id/EDIT_RIGHT" in my xml, the focus doesn't goes to the right edittext but goes to edittext under the left one.

enter image description here

    <!-- EDIT LEFT-->
    <EditText
        android:id="@+id/EDIT_LEFT"
        android:layout_width="165dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="10dp"
        android:hint="@string/edit_left_hint"
        android:nextFocusRight="@id/EDIT_RIGHT"
        tools:ignore="Autofill"/>

    <!-- EDIT RIGHT-->
    <EditText
        android:id="@+id/EDIT_RIGHT"
        android:layout_width="165dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:hint="@string/edit_right_hint"
        android:nextFocusDown="@id/EDIT_DOWN"
        tools:ignore="Autofill"/>

Upvotes: 1

Views: 805

Answers (2)

Sumit Ranjan
Sumit Ranjan

Reputation: 1

Insted of using android:nextFocusDown="@id/EDIT_DOWN".

Use android:nextFocusForward="@+id/EDIT_DOWN".

<EditText
    android:layout_width="250dp"
    android:layout_height="@dimen/edt_height"
    android:background="@drawable/edt_back_shape"
    android:hint="Enter email"
    android:layout_marginStart="@dimen/size_5dp"
    android:text="@={viewmodel.email,default=``}"
    android:paddingStart="@dimen/size_10dp"
    android:id="@+id/emailEdt"
    android:inputType="textEmailAddress"
    android:imeOptions="actionNext"
    android:nextFocusForward="@+id/websiteEdt"
    android:textSize="@dimen/form_edt_text_sizes"
    app:layout_constraintStart_toEndOf="@+id/stNoEdt"

    app:layout_constraintTop_toBottomOf="@+id/emailTitle"
    android:fontFamily="@font/poppins_light"
/>

Upvotes: 0

Anupam
Anupam

Reputation: 2853

You have to use like this -

<!-- EDIT LEFT-->
    <EditText
        android:id="@+id/EDIT_LEFT"
        android:layout_width="165dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="10dp"
        android:hint="@string/edit_left_hint"
        android:imeOptions="actionNext"
        android:nextFocusRight="@+id/EDIT_RIGHT"
        tools:ignore="Autofill"/>

    <!-- EDIT RIGHT-->
    <EditText
        android:id="@+id/EDIT_RIGHT"
        android:layout_width="165dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:hint="@string/edit_rgiht_hint"
        android:imeOptions="actionNext"
        android:nextFocusDown="@id/EDIT_DOWN"
        tools:ignore="Autofill"/>

You should use android:nextFocusRight="@+id/EDIT_RIGHT" instead of android:nextFocusRight="@id/EDIT_RIGHT" because you are using this edittext before creating it and use imeOptions.

Upvotes: 2

Related Questions