4

according to the official site, Android supports forward declarations from version 1.6 onwards.

Having adjusted the min SDK and target SDK requirements both to '4' in manifest.xml, the layout editor from eclipse is still complaining about unknown declarations in a relative layout:

<xml>

<CheckBox 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  android:id="@+id/ChkBoxSaveuser"
  android:text="@string/options_saveuser"
  android:layout_above="@id/ChkBoxSavePwd"
  android:layout_marginTop="20dp"
  android:layout_alignLeft="@id/EditTxtServer"/>

 <EditText 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:id="@+id/EditTxtServer" 
  android:maxLines="1"
  android:minWidth="200dp"
  android:layout_marginTop="10dp"
  android:layout_gravity="center_horizontal"
  android:layout_above="@id/ChkBoxSaveuser"/>

</xml>

Multiple annotations found at this line:

  • ERROR Error: No resource found that matches the given name (at 'layout_above' with value '@id/ ChkBoxSavePwd').

  • ERROR Error: No resource found that matches the given name (at 'layout_alignLeft' with value '@id/EditTxtServer').

clean / rebuilding did not help.. anyone stumbled upon this matter ?

Zoe
  • 27,060
  • 21
  • 118
  • 148
kellogs
  • 2,837
  • 3
  • 38
  • 51

1 Answers1

17

To use forward references, declare the reference (use the "@+id/..." notation) the first time you use the reference, not on the actual element.

<xml>

<CheckBox 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  android:id="@+id/ChkBoxSaveuser"
  android:text="@string/options_saveuser"
  android:layout_above="@+id/ChkBoxSavePwd"
  android:layout_marginTop="20dp"
  android:layout_alignLeft="@+id/EditTxtServer"/>

 <EditText 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:id="@id/EditTxtServer" 
  android:maxLines="1"
  android:minWidth="200dp"
  android:layout_marginTop="10dp"
  android:layout_gravity="center_horizontal"
  android:layout_above="@id/ChkBoxSaveuser"/>

</xml>
William Scott
  • 2,109
  • 1
  • 24
  • 21