2014-12-13 78 views
0

它说我的EditTexts无效。 我不知道它有什么问题,但更具体的说,android:id是无效的。布局无效(EditText)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".SettingsActivity"> 
    <TextView 
     android:id="@+id/text_view_header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:textColor="#FF0000" 
     android:textSize="20sp" 
     android:text="Testapp" /> 
    <EditText 
        android:id="@+id/host" 
        android:layout_width="fill_parent" 
     android:gravity="center_horizontal" 
        android:layout_height="wrap_content" 
     android:layout_below="@+id/text_view_header" 
      android:inputType="textNoSuggestions" 
        android:hint="@string/host" /> 
    <EditText 
        android:id="@+id/host2" 
        android:layout_width="fill_parent" 
     android:gravity="center_horizontal" 
        android:layout_height="wrap_content" 
     android:layout_below="@+id/spyhost" 
     android:inputType="textNoSuggestions" 
        android:hint="@string/host2" /> 
    <Button 
     android:id="@+id/save" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:layout_below="@+id/vidhost" 
     android:text="Save Settings" 
     android:onClick="onClickSave" /> 
</RelativeLayout> 

编辑:修复很简单。有些字符不会显示,所以用新空格或制表符替换所有空格。原因很可能是从网站复制内容。由于在@Squonk

+0

您的EditTexts和Buttons每个都有一个'android:layout_below'属性,但是在那个'RelativeLayout'中没有任何与这些属性相关联的id的小部件。 – Squonk 2014-12-13 11:45:35

回答

0
android:layout_below="@+id/text_view_header" 

应该

android:layout_below="@id/text_view_header" 

在layout_below属性不应该有“+”号id.And前layout_below设置元素的ID应该在同一个父布局作为layout_below设置的元素。在你的代码中,第二个edittext,即host2 edittext有layout_below属性,其中id是spyhost,但是没有这样的元素,spyhost id定义了相对布局。按钮也有类似的问题。