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" 

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"

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.

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: Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s