android – What is the difference between "@id" and "@+id"?

Question:

When creating a component, we use @+id/nome to identify it.

For example:

<TextView 
            android:id="@+id/tv_fornecedor"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Fornecedor:"/> 

What's the difference between using @id/nome (without the +) instead of @+id/nome ?
Is it okay to use one or the other?

Answer:

@+id/nome is to associate a name to the component, it creates an entry in the R class.

@id/nome only identifies/references the component, as in a RelativeLayout when you want to indicate the position of a component in relation to another.

@id/nome can only be used after using @+id/nome .

If you want you can use only and always @+id/nome

Scroll to Top