1

Today reading a tutorial i see the XML layout and see some elements have a id like

android:id="@android:id/element_id"

others have the regular android:id

android:id="@+id/element_id"

What is the difference between these two lines?

Donato Szilagyi
  • 4,279
  • 4
  • 36
  • 53
rkmax
  • 17,633
  • 23
  • 91
  • 176
  • Possible duplicate of [When should i use @android:id/?](http://stackoverflow.com/questions/5635826/when-should-i-use-androidid) ([Difference between “@id/” and “@+id/” in Android](http://stackoverflow.com/questions/5025910/difference-between-id-and-id-in-android) may also be of interest) – Cat Mar 19 '13 at 00:49

2 Answers2

2

the one with the '+' will force the compiler to create that element in your R.java. You use the + when it is the first time creating a reference to that id. In other elements that refer to it, you do not need the '+' since its static entry in the R.java will already be there. A more eloquent explanation of this same issue is found here : what is the difference betwenn @id/ and @+id/ in android?

Community
  • 1
  • 1
munch1324
  • 1,148
  • 5
  • 10
1

The first one is using an ID defined by the Android framework (hence, the android: prefix).

The second one is declaring a new ID for use within your app.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491