Android XML - 在EditText字段之间移动

Dar*_*ren 6 xml android android-edittext

我有两个碎片,上面有几个EditText框.它们都是相似的,但是非常奇怪的是,1将在EditText字段之间切换,但另一个不会.

这是我遇到的问题:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/loginparent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff008DFF" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dip"
        android:background="#ff008DFF"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="40dip"
            android:contentDescription="@string/logoDesc"
            android:src="@drawable/logo1" />

        <EditText
            android:id="@+id/usernameLog"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:hint="@string/username"
            android:imeOptions="actionNext"
            android:singleLine="true"
            android:textSize="14sp" />

        <EditText
            android:id="@+id/passwordLog"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/password"
            android:imeOptions="actionDone"
            android:inputType="textPassword"
            android:singleLine="true"
            android:textSize="14sp" />

        <Button
            android:id="@+id/loginButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/login" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dip" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:text="@string/newuser"
                android:textColor="#ffffffff"
                android:textSize="14sp" />

            <Button
                android:id="@+id/viewSignupBtn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/signup" />
        </LinearLayout>
    </LinearLayout>

    <ProgressBar
        android:id="@+id/progressBarLog"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:padding="70dip"
        android:visibility="gone" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

当我从第一个EditText框中选中时,焦点消失,然后在第二个选项卡上将焦点移动到第二个字段.如果我选择焦点,则再次相同,然后再次选项卡,它会出现在它下面的按钮上.

除了获取指向EditText字段的指针外,Fragment的onCreateView没有什么特别之处.就像我说的,我的第二个视图非常相似,工作正常.

当我选中时,我注意到我在Logcat中显示了这些警告:

04-24 19:31:29.695: D/InputEventConsistencyVerifier(2040): KeyEvent: ACTION_UP but key was not down.
04-24 19:31:29.695: D/InputEventConsistencyVerifier(2040):   in android.support.v4.app.NoSaveStateFrameLayout@40f365b8
04-24 19:31:29.695: D/InputEventConsistencyVerifier(2040):   0: sent at 4325570000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=4325570, downTime=4325514, deviceId=0, source=0x101 }
04-24 19:31:31.076: D/InputEventConsistencyVerifier(2040): KeyEvent: ACTION_UP but key was not down.
04-24 19:31:31.076: D/InputEventConsistencyVerifier(2040):   in android.widget.EditText@40f78e98
04-24 19:31:31.076: D/InputEventConsistencyVerifier(2040):   0: sent at 4326945000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=4326945, downTime=4326889, deviceId=0, source=0x101 }
04-24 19:31:32.255: D/InputEventConsistencyVerifier(2040): KeyEvent: ACTION_UP but key was not down.
04-24 19:31:32.255: D/InputEventConsistencyVerifier(2040):   in android.widget.EditText@40f73678
04-24 19:31:32.255: D/InputEventConsistencyVerifier(2040):   0: sent at 4328123000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=4328123, downTime=4328053, deviceId=0, source=0x101 }
Run Code Online (Sandbox Code Playgroud)

编辑-----------------

好的,正如评论中所建议的那样,我将onFocusChanged监听器添加到所有视图(通过它们循环并添加了监听器)并记录了视图的内容.每次我选项卡,我都会得到日志,但奇怪的是,我选中了第一个EditText框,日志说editText框有焦点,我再次选项卡,焦点丢失,但日志显示同一个EditText框有焦点!再次选项卡,第二个获得焦点,日志显示正确的ID,标签再次焦点​​丢失,但再次登录说第二个EditText框有焦点,即使它没有!

非常奇怪的行为.

Phi*_*hil 5

正如 @Delyan 所建议的,您应该能够添加 XML 属性来控制此行为。但是,您可能想尝试使用其他android:nextFocus____属性之一,例如android:nextFocusForward. 这些属性的完整列表可在此处和下面找到。