Tuesday, December 22, 2009

The difference between @+id and @android:id

Sometimes you see references in your layout files like:

<listview id="@+id/android:list">


<listview id="@android:id/list">

What's the difference?
.. I'm glad you asked

@+id/foo means you are creating an id named foo in the namespace of your application.
You can refer to it using @id/foo.
@android:id/foo means you are referring to an id defined in the android namespace.

The '+' means to create the symbol if it doesn't already exist. You don't need it (and shouldn't use it) when referencing android: symbols, because those are already defined for you by the platform and you can't make your own in that namespace anyway.

This namespace is the namespace of the framework.
for example, you need to use @android:id/list because this the id the framework expects to find.. (the framework knows only about the ids in the android namespace.)

1 comment: