0

我正在为注册屏幕执行此操作。我有三个字段电子邮件,生日和密码。在生日编辑文本中,我正在显示生日选择器对话框。我不想让用户通过键入来更新生日。这就是为什么我将可聚焦为“假”而可点击为“真”。

    <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>

但是当用户在电子邮件编辑文本上按“下一步”时,它会直接转到最后一个密码。它跳过第二个文本字段。

在场景中应该做什么?

4

2 回答 2

2

我使用这段代码解决了这个问题。

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

我正在模拟生日的点击事件,因为它会在按下“下一步”时显示生日选择器,同时为实名字段显示键盘。

于 2014-05-23T12:46:57.053 回答
0

您可以使用 xml 标签android:nextFocusDown="@id/yourNextElementID"来实现这一点。

在你的情况下,这样的事情email EditText应该可以工作:

android:nextFocusDown="@+id/birthdate"

检查有关它的android文档

编辑:

另一种可能有效的解决方案是以编程方式进行。它可以确保您创建了您的对象,并且onClick正确地调用了您的对象。

yourEmailEditText.setNextFocusDownId(R.id.birthdate); 
于 2014-05-21T09:22:35.340 回答