android - EditText 焦点跨布局不一致

标签 android xml orientation

我有两个不同的 main.xml 文件,一个用于纵向,一个用于布局。每个人在 ScrollView 内的 RelativeLayout 内都有此代码。

<LinearLayout
    android:id="@+id/name_phone"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/acquire"
    >
    <EditText
        android:id="@+id/name"
        android:inputType="textPersonName"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="observer name"
        android:nextFocusDown="@id/phone"
        android:background="@android:drawable/editbox_background"               
        />
    <EditText
        android:id="@+id/phone"
        android:inputType="phone"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="phone number"
        android:nextFocusDown="@id/phone"
        android:background="@android:drawable/editbox_background"
        />
    </LinearLayout>

等...

奇怪的是:据我所知,你不应该能够引用 xml 中尚未发生的事情,所以 android:nextFocusDown="@id/phone"应该失败,因为电话还没有已宣布;这就是我的横向 xml 中发生的情况,但不是纵向的。在纵向模式下,它可以完美地工作,并且可以顺利地通过所有四个 EditTexts 传递焦点。如果我将 NextFocusDown 放入景观中,它将无法编译,并显示“找不到与给定名称匹配的资源(在 'nextFocusDown' 中值为 '@id/phone')。”

最好有解决方案或解释。我的想法是,我在两个不同的 LinearLayouts 中有四个文本框,首先获得焦点的那个将把它传递给它下面的 EditText,跳过其他的。我希望它能像我在纵向布局中那样工作,当用户点击名称上的下一个时,焦点移动到电话,当他们点击下一个时,它移动到电子邮件等。我也很好奇为什么会这样让这个工作在纵向而不是横向。

最佳答案

这是一个非常古老的帖子,但我会尽我所能回答它。据我所知,您在第一次引用 id 时放置了 + 号,所以在您的: android:nextFocusDown="@id/phone" 实际上应该是 android:nextFocusDown="@+id/phone 因为这是你第一次引用那个对象。然后取出你有的+号 android:id="@+id/phone"

希望这对遇到此问题的任何人有所帮助。

关于android - EditText 焦点跨布局不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5943414/

相关文章:

android - Dialog Fragment 无法将事件回传给 Android 中的调用 Fragment?

android - 使用 JayData for Android/Phone Gap 访问 Sqlite 数据库

jquery - 如何使用用户上传的XML文件?

ios - io6 允许基于某些条件的界面方向

ios - 在 Swift 中获取设备方向

ios - 在 Swift 中,如何在启动后立即正确获取设备方向?

Android ExpandableListView 隐藏组

android - RxJava + RxAndroid WidgetObservable 新 API

xml 中的 Android 谷歌地图 fragment 。我得到 "Unexpected namespace prefix"

php - 使用 XML 进行实时搜索。错还是对?