-1

According to this thread I need to use @+id/ for the first time to make resource be created.

But what if I forget that this resource was previously created and create it again with @+id/? I have some input and set nextFocusDown for the element that is still not declared.

<EditText 
...
android:nextFocusDown="@+id/myinput2"/>

200 lines below I create this element with @+id because I forgot that it's already declared.

<EditText 
...
android:id="@+id/myinput2"/>

It works like this but can it cause an issue?

Vitalii
  • 10,091
  • 18
  • 83
  • 151

3 Answers3

1

It works like this but can it cause an issue?

No, it can't. Always use @+id/. By now, the Android build environment is smart enought to figure it out.

David Medenjak
  • 33,993
  • 14
  • 106
  • 134
1

Some quick definitions:

  • @+id/foo means "use the id foo, and create it if it doesn't exist"
  • @id/foo means "use the id foo" (which will be an error if the id foo doesn't exist)

Previously, there were reasons to prefer @id over @+id (the system could tell you if you tried to reference a view via an id that didn't exist), but now the system is smart enough that even writing android:layout_below="@+id/idthatdoesntexistanywhere" will be tagged as an error:

enter image description here

So just always use @+id.

Ben P.
  • 52,661
  • 6
  • 95
  • 123
0

If you put two elements with the same id in the same layout file, it generates an IDE error (red underline) and you won't be able to compile.

Pier Giorgio Misley
  • 5,305
  • 4
  • 27
  • 66