0

I am doing this for signup screen. I am having three fields email, birthdate and password. In birthdate edit text I am displaying birthdate picker dialog. I don't want to let user update birthdate by typing. That's why i gave focusable as "false" and clickable as "true".

    <LinearLayout
        android:id="@+id/signup_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/bg"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/email"
            style="@style/big_centered_textfield_style"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:background="@drawable/rounded"
            android:hint="Email address 320"
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:paddingBottom="5dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="5dp"
            android:textSize="@dimen/normal_font" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/birthdate"
            style="@style/big_centered_textfield_style"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="@drawable/rounded"
            android:clickable="true"
            android:focusable="false"
            android:hint="@string/birthdate"
            android:inputType="date"
            android:maxLines="1"
            android:onClick="birthdateClicked"
            android:paddingBottom="5dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="5dp"
            android:textSize="@dimen/normal_font" >
        </EditText>

        <EditText
            android:id="@+id/password"
            style="@style/big_centered_textfield_style"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="@drawable/rounded"
            android:hint="@string/password"
            android:inputType="textPassword"
            android:maxLines="1"
            android:paddingBottom="5dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="5dp"
            android:textSize="@dimen/normal_font" >
        </EditText>

    </LinearLayout>

But when user presses "Next" on email edit text, it directly goes to password that is last. It skips second text field.

What should be done in the scenario?

keen
  • 3,001
  • 4
  • 34
  • 59

2 Answers2

2

I solved this issue using this code.

realName.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId,
                KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_NEXT) {
                birthdate.performClick();
            }
            return false;
        }
    });

I am simulating click event for birthdate as it will display birthdate picker on "Next" pressed while key board is being displayed for realname field.

keen
  • 3,001
  • 4
  • 34
  • 59
0

You can use the xml tag android:nextFocusDown="@id/yourNextElementID" to achieve this.

In your case something like this in the email EditText should work:

android:nextFocusDown="@+id/birthdate"

Check the android documentation about it.

Edit:

Another solution that may work is to do it programmatically. It can ensure you that your object is created and the call to your onClick will be correctly made.

yourEmailEditText.setNextFocusDownId(R.id.birthdate); 
calimbak
  • 856
  • 13
  • 21
  • I already tried it but it skips edit text for birthdate. I think it's because i gave focusable "false". When I changed it to true it goes to birthdate edit text but problem is it displays default keyboard and not calling birthdateClicked method that I use to display date picker. – keen May 21 '14 at 10:02