Search code examples
androideclipseandroid-relativelayoutforward-declarationandroid-sdk-1.6

android forward declarations not working in 1.6


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 ?


Solution

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