Android的XML - 的EditText字段之间移动 [英] Android XML - moving between EditText fields

查看:403
本文介绍了Android的XML - 的EditText字段之间移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2片段有几个的EditText框。他们都制定了类似的,但它很奇怪,的EditText字段之间1意志选项卡,但对方不会。

I've got 2 Fragments that have a couple of EditText boxes on. They are both laid out similar, however its very strange that 1 will tab between the EditText fields, but the other won't.

这是一个我遇到的问题有:

This is the one i'm having problems with:

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

当我从第一次的EditText框选项卡,焦点就会消失,然后第2个选项卡就可以了移动焦点到第二场。同样的,如果再我选项卡焦点转移,然后再和标签它出现在它下面的按钮。

When I tab from the first EditText box, the focus disappears then on a 2nd tab it moves focus to the 2nd field. Same again if I tab focus goes, then tab again and it appears on the button below it.

没有什么特别的,从获得指针到的EditText字段在片段的onCreateView事情分开。就像我说的,我有一个第二观点非常相似,以至于正常工作。

There's nothing special going on in the Fragment's onCreateView apart from getting pointers to the EditText fields. Like I say, I have a 2nd view very similar that works fine.

当我选项卡,我发现我得到这些警告显示在logcat中了:

When I tab, I notice I get these warnings showing up in 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 }

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

EDIT -----------------

好吧,如评论所说,我加入onFocusChanged听众各方意见(通过他们所有的毛圈绒并添加监听器)和已记录什么看法。每次我选项卡,我得到的日志,但奇怪的是,我卡到了第一的EditText框和日志说,EDITTEXT框具有焦点,我选项卡再次聚焦丢失,但日志也说了同样的EditText框具有焦点! 标签再次,第二获得焦点和日志说,正确的ID,标签再次聚焦丢失,但再次登录表示,第二届的EditText框具有焦点,即使它有没有!!

Ok, as suggested in comments, I added onFocusChanged listeners to all views (Looped through them all and added listener) and Logged what the view is. Each time I tab, I get the log but the strange thing is, I tab to the first EditText box and the Log says that editText box has focus, I tab again and focus is lost but the log says the same EditText box has focus! Tab again and the second gets focus and log says the correct id, tab again focus lost but again log says the 2nd EditText box has focus even though it hasn't!!

很奇怪的行为。

推荐答案

由于@Delyan建议,你应该能够添加一个XML属性来控制此行为。但是,您可能想尝试使用其他一款使用Android操作系统:的nextfocus ____ 属性,如安卓nextFocusForward 。这些属性的完整列表,请这里及以下

As @Delyan suggests, you should be able to add an XML attribute to control this behavior. However, you may want to try using one of the other android:nextFocus____ attributes, such as android:nextFocusForward. A full list of these attributes is available here and below.

这篇关于Android的XML - 的EditText字段之间移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆