What’s the difference between "@id" and "@+id"?

Asked

Viewed 1,896 times

27

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

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 of using @id/nome (without the +), in place of @+id/nome ?
It’s okay to use one or the other?

1 answer

46


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

@id/nome only identifies/references the component, for example in a Relativelayout when one wants to indicate the position of one component relative to another.

@id/nome may be used only after the use of @+id/nome.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.