2014-12-13 75 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定義了相對佈局。按鈕也有類似的問題。