Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is different between @+id/android:list and @id/android:list?

Tags:

syntax

android

I've develop android application, and one question.

As you know, When we use LiveActivity, we must specify @id/android:list for ListView ID.

But, When I use @+id/android:list instead of @id/android:list, it is working fine.

What is different between @+id/android:list and @id/android:list ??

like image 384
James Lee Avatar asked Jul 16 '10 11:07

James Lee


2 Answers

The fundamental difference between @ and @+ is that @+ is signaling that you need to add a new id, the @ by itself tells the compiler to look for an existing id.

like image 143
ryangavin Avatar answered Nov 16 '22 02:11

ryangavin


As you know, When we use LiveActivity, we must specify @id/android:list for ListView ID.

No, you do not. You must specify @android:id/list for the ListView ID for use with ListActivity.

But, When I use @+id/android:list instead of @id/android:list, it is working fine.

No, those will give you compile errors. Colons are not valid characters in Java field names, and so those IDs are illegal.

Switching back to legal Android syntax, if you are declaring your own ID (no android: in the value), the first time you use the ID in a file, you are supposed to have the + sign. The second and subsequent times, the + sign is not needed, though it seems to cause no harm if you have in there as well.

like image 23
CommonsWare Avatar answered Nov 16 '22 02:11

CommonsWare