Focus on last edittext in Custom Dialog doesn't work

411 views Asked by At

In my App I'm using a Custum Dialog (android.app.Dialog) with three Edit Texts in it. I'm able to set the next focus from the first to the second EditText when I press the next Button on the SoftKeyboard, but it doesen't work to set the focus on the third EditText. I already tried to set nextFocusForward or nextFocusDown and so on but it still doesn't work.

Here is the XML Layout from my Custom Dialog:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/addcard_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:src="@drawable/dialog_addcard_info" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <EditText
            android:id="@+id/addcard_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:hint="@string/name"
            android:inputType="text"
            android:lines="1"
            android:maxLines="1"
            android:scrollHorizontally="true" />

        <EditText
            android:id="@+id/addcard_number"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="8dp"
            android:hint="@string/number"
            android:inputType="number"
            android:maxLength="16"
            android:scrollHorizontally="true"/>

        <EditText
            android:id="@+id/addcard_pin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="8dp"
            android:hint="@string/pin"
            android:inputType="numberPassword"
            android:maxLength="4"
            android:textSize="14sp"
            android:scrollHorizontally="true"/>
    </LinearLayout>


    <TextView
        android:id="@+id/addcard_errormessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:text="@string/error"
        android:textColor="#ff0000"
        android:textStyle="bold"
        android:visibility="gone" />

    <Button
        android:id="@+id/addcard_verify"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:text="@string/verify" />
</LinearLayout>

Does anyone have an idea why i'm not able to set the focus on the third EditText? Thanks in advance.

1

There are 1 answers

1
Android Mediocre On BEST ANSWER

try this one in your code :)

<EditText
   android:id="@+id/addcard_number"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_marginLeft="16dp"
   android:layout_marginRight="16dp"
   android:layout_marginTop="8dp"
   android:hint="@string/number"
   android:inputType="number"
   android:maxLength="16"
   android:imeOptions="actionNext" // try this one
   android:nextFocusDown="@+id/addcard_errormessage" // and add this one
   android:scrollHorizontally="true"/>