Reputation: 31
When declaring the id there is a "+" sign but when referencing it there is no sign. Why is that? What is the function of the + sign?
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type here:"/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label"/>
Upvotes: 3
Views: 168
Reputation: 11
A quote from a webpage explaining android:id :
Using the plus sign is necessary only when specifying a new resource ID and not needed for concrete resources such as strings or layouts.
Table 1 on this webpage about providing resources on developer.android.com, consists of all the resources for which you do not use @+id
Upvotes: 1
Reputation: 1006779
When declaring the id there is a "+" sign but when referencing it there is no sign.
That is not strictly accurate.
The +
sign is used on the first occurrence of the ID in the layout resource, and indicates that we are allocating a new ID. The +
can be left off subsequent occurrences, indicating that we are trying to use a pre-defined ID.
Upvotes: 2
Reputation: 6263
There are two possibilities, @id/
and @+id/
.
@+id
is used when adding a new id. @id/
is used to reference an existing id.
The +
sign implies this id is new, and is not an update of an existing one.
Upvotes: 2
Reputation: 21507
The + creates an id that lets you reference the TextView and EditText objects in your java code. So if you wanted to access the TextView you created in your java code, you could access it via R.id.label
. And the EditText can be accessed via R.id.entry
Upvotes: 2