Reputation: 1896
<?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?
Upvotes: 0
Views: 831
Reputation: 289
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"
Upvotes: -1
Reputation: 2985
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
Upvotes: 4