Reputation: 81721
I couldn't come up with a better title for this question, so please feel free to amend it if you can.
So here is my question. I decided to write a small app for myself and along the way I am also trying to learn Android Development better. I know why there is a +
(plus) sign in the android:id
attribute as it means "creating a new id resource". But I don't know why Android needs to put +
in the ones used for referencing such as below:
Here I have two buttons named StartButton
and StopButton
and as they are new resources, the android:id
contains +
:
<Button
android:id="@+id/StartButton"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="53dp"
android:textSize="18dp"
android:text="Start"
android:onClick="StartButton_OnClick" />
<Button
android:id="@+id/StopButton"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/StartButton"
android:layout_toRightOf="@+id/StartButton"
android:text="Stop"
android:textSize="18dp"
tools:context=".CallerBlockerActivity"
android:onClick="StopButton_OnClick" />
But why android:layout_alignTop
contains +
puzzles me since id/StartButton
is defined when @id/StopButton
reaches it. Can some one please explain the necessity of this syntax?
Upvotes: 4
Views: 273
Reputation: 134664
It doesn't matter either way -- there only needs to be a + for the first reference to an ID. If the ID is already defined, the + is ignored anyway. You could place a + before every reference in the XML if you wanted to, and everything would work as expected. It's only necessary for the first reference, though.
Upvotes: 5