Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between @+id/android:list and @+id/list

Tags:

I am wondering what's the difference between @+id/android:list and @+id/list. I know the last one which is a regular id assignment but the first looks different. What makes it special?

Where I saw it: I was studying on ListView, ListAdapter and things like that and the author define the ListView in layout xml file as below :

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    > <ListView     android:id="@+id/android:list"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     /> <TextView     android:id="@+id/android:empty"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:text="@string/main_no_items"/> </LinearLayout> 

and also let me mention @+id/android:empty id as well.

And he also extends ListActivity class.

Here is the source of the article.

And also what's in my mind as questions are :

  1. Should we extend ListActivity? Maybe I want an Activity which also contains other Views.
  2. We use @+id/android:list just because we extend ListActivity or we can use the same convention if we extend Activity?

Thanks.

like image 466
Tarik Avatar asked Dec 04 '10 20:12

Tarik


People also ask

What's the difference between @ID and @+ id?

Exactly from docs: The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R. java file).

What is an ID in Android?

The Android unique device ID is called the Android Advertising ID (AAID). It's an anonymized string of numbers and letters generated for the device upon initial setup.

Why ID is used in Android?

Android ID is an unique ID to each device. It is used to identify your device for market downloads, specific gaming applications that needs to identify your device (so that they know it's a device that was used to pay for the application) and such.

Is resource ID same as ID?

IDs and Identifiers Despite the similar names, these are not the same thing. A resource ID is the portion of the resource address/URL that comes after the resource type. For example, the resource Patient/123 has the ID of 123.


1 Answers

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.

EDIT: Need to add the corrections David Hedlund pointed out: The proper reference would be @android:id/list. Also, + indicates you're defining a new ID - you obviously don't need that when you're referencing something that was defined in the Android API.

like image 63
EboMike Avatar answered Sep 28 '22 07:09

EboMike