Android:layout_toLeftOf ~ No resource found

831 views Asked by At
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView
        android:id="@+id/pickerDialog_title"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:gravity="left|center_horizontal"
        android:text="HELLO WORLD!!" />
    <NumberPicker
        android:id="@+id/pickerDialog_selector"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/pickerDialog_title" />
    <Button
        android:id="@+id/pickerDialog_cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/pickerDialog_selector"
        android:layout_toLeftOf="@id/pickerDialog_set" //Cannot find @id/pickerDialog_set
        android:gravity="center"
        android:text="Cancel" />
    <Button
        android:id="@+id/pickerDialog_set" //Here it is
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/pickerDialog_selector"
        android:layout_toRightOf="@id/pickerDialog_cancel"
        android:gravity="center"
        android:text="Set" />
</merge> 

No resource found that matches the given name (at layout_toLeftOf with value @id/pickerDialog_set

It was my understanding that, android:id should be prefixed as @+id/, with reference made to the view to be prefixed as @id/

How do i reference ids correctly?

3

There are 3 answers

0
Gabriella Angelova On BEST ANSWER

You should change the order of the Button that is toLeftOf the one this one button, because you can not use an id, before it is created. Your code should looks like this:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView
        android:id="@+id/pickerDialog_title"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:gravity="left|center_horizontal"
        android:text="HELLO WORLD!!" />
    <NumberPicker
        android:id="@+id/pickerDialog_selector"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/pickerDialog_title" />
    <Button
        android:id="@+id/pickerDialog_set" //Here it is
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/pickerDialog_selector"
        android:gravity="center"
        android:text="Set" />
    <Button
        android:id="@+id/pickerDialog_cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/pickerDialog_selector"
        android:layout_toLeftOf="@id/pickerDialog_set" 
        android:gravity="center"
        android:text="Cancel" />
 </merge> 

and remove the android:layout_toRightOf of the pickerDialog_set Button like I did in the code above

3
Eddwhis On

Try this android:layout_toLeftOf="@+id/pickerDialog_set".

0
theMfromA On

You have to add the sign "+" when you add the id for the first time in your layout (from top to bottom). So this should do the trick:

android:layout_toLeftOf="@+id/pickerDialog_set"