0

The question is how can I refer to id from include tag?

Let`s look at the example:

I have got such view that I want to reuse in many places:

<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/first_el"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Some txt 1" />
</merge>

Now I want to include this view and add some other view below like this:

<RelativeLayout>
    <include layout="@layout/above_view"/>
    <TextView
        android:id="@+id/third_el"
        android:layout_alignRight="@id/first_el"
        android:layout_below="@id/first_el"
        android:text="Some txt 2" />
</RelativeLayout>

In this case I receive error:

Description Resource Path Location Type error: Error: 
No resource found that matches the   given name (at 'layout_alignRight' with value '@id/first_el').

Regards

Michal
  • 2,074
  • 2
  • 22
  • 29

1 Answers1

1

The problem could be because you are missing "+" in the layout_alignRight attribute.

I think you might have to change android:layout_alignRight="@id/first_el"

to

 android:layout_alignRight="@+id/first_el"
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
  • 1
    look at the first XML, he defines that id, and shouldn't do it in the second. – MByD Apr 18 '12 at 11:04
  • 1
    @Binyamin Sharet... Andro Selva is correct. Even though it is defined as the id, you must use the `@+id/` again to reference it. From what I understand, you use `@id/` when you define IDs in res/values/ids.xml. See this post for more info: See this post for additional info: http://stackoverflow.com/questions/5025910/difference-between-id-and-id-in-android – Alex Fu Apr 18 '12 at 11:09