8

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 ??

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
James Lee
  • 81
  • 2

4 Answers4

7

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.

Ilya Kogan
  • 21,995
  • 15
  • 85
  • 141
ryangavin
  • 424
  • 2
  • 6
  • Also the R.xxx generator looks for @+id afaik. It's a bit of wacky naming system if you've used XAML – Chris S Oct 19 '10 at 09:27
4

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • But, I've found reference for ListActivity in Android Developers. and you can see @id/android:list in sample code if you click below link. http://developer.android.com/reference/android/app/ListActivity.html sample code: ... – James Lee Jul 16 '10 at 13:04
  • 1
    @CommonsWare When determining what is "the first time you use the ID in a file", do includes get inlined / counted or not? – sschuberth Jan 17 '13 at 15:21
  • @sschuberth: Good question. I am not really certain, as I do not use `` all that much. – CommonsWare Jan 17 '13 at 15:31
1

Resource IDs in Android are specific to a package (which is good, or else you'd have lots of conflicts if your app is dealing with several packages at the same time).

@+id/list will create a resource ID in your app (=your package) with the name "list" and give it a unique ID. In code, that would be R.id.list.

@android:id/list will use the ID "list" from the package android (which, in code, would be android.R.id.list.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
1

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

It seems that there are two ways to reference to the platform id android.R.id.list: @android:id/list and @id/android:list. The ListActivity documentation shows both (the first one in text, second in the example) but does not clarify if there's any difference.

The @+id/android:list as the ListView's id seems to work too. I assume that what happens here is that a copy of the android.R.id.list identifier is added to the application's own ID list.

In my opinion @android:id/list is the clearest way for referencing to android.R.id.list.

Community
  • 1
  • 1
apa64
  • 1,578
  • 1
  • 17
  • 26