11
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
  <ListView
      android:layout_above="@id/btn_4"    <-- this line error: No resource found
      android:layout_width="match_parent"
      android:layout_height="200dp" />
  <Button android:id="@+id/btn_4"         <-- I declare the id here
      android:layout_alignParentBottom="true"
      android:layout_height="wrap_content"
      android:layout_width="match_parent" />
</RelativeLayout>

Any suggestions?

Onik
  • 19,396
  • 14
  • 68
  • 91
Eric Lin
  • 333
  • 2
  • 4
  • 15

3 Answers3

27

As I understand it, the first time an id is used in a layout xml, it needs to have a + sign in front of it.

From the Declaring Layout docs:

The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file).

So, add a '+' to the first btn_4 reference in the ListView layout and you can remove the unnecessary '+' from the android:id attribute in the Button layout.

Pete Richardson
  • 723
  • 6
  • 10
3

When you declare relative layouts, you have to use android:layout_above="@+id/layoutToBeAbove"

Otherwise, the system does not know what you're pointing at.

This declaration will point at the same resource.

Hope this helped!

Codeman
  • 12,157
  • 10
  • 53
  • 91
2

Declare the ListView list_1 after declaring the Button btn_4 as it tries to reference it in android:layout_above="@id/btn_4".

Che Jami
  • 5,151
  • 2
  • 21
  • 18
  • XML is a markup language, there is no "execution order", as it is stateless. It doesn't matter where it is declared, it simply has to have correct markup. – Codeman Aug 15 '11 at 14:41
  • 2
    Eh? XML is what you make of it. I can parse it top-down if I want to (order is maintained). It *does* fix the issue. Imagine if A could declare itself above B and B declare itself above A. – Che Jami Aug 15 '11 at 14:44