Android Programming: @android:id/list vs @+id/list

Ran into this problem today in a layout. Threw me off for a bit.  What’s the difference if I declare an ID @android:id/list vs @+id/list?

For Example

<ListView android:id="@android:id/list" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

The tutorial explains it like this:

The @ symbol in the id strings of the ListView and TextView tags means that the XML parser should parse and expand the rest of the id string and use an ID resource.

The list and empty IDs are provided for us by the Android platform, so, we must prefix the id with android: (e.g.,@android:id/list).

<TextView android:id="@+id/text1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

The tutorial explains it like this:

In this case we create a new id called text1. The + after the @ in the id string indicates that the id should be automatically created as a resource if it does not already exist, so we are defining text1 on the fly and then using it.

Advertisements
This entry was posted in Coding, troubleshooting and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s