Saturday, February 19, 2011

Android Resource ID Format

When defining resource for Android, the format of resource id attribute looks like android:id="@+id/item01"

The '@' at the beginning of the string is just a delimiter, and indicates that the following string is an ID resource.

The '+' means that this is a new resource id that must be created and added to the resource R file. However if the same resource ID are defined more than once, only one ID is included in R file.

The 'id/item01' is the class and data member name included in the generated R class. The resource can be referred as R.id.item01. The class name is required, so just define 'item01' is invalid. If the resource id is defined as android:id="@+idd/ddd/item01", then the generated R file only includes R.idd.ddd as the reource id.

Do not mix resource id with resource name. Resource name is used to identify a resource. Some resource includes a list of items, like menu items in a menu resource, so resource id can be used to identify a particular item in the list.

Jonathan

No comments:

Post a Comment