Public static final int hello0x7f040000 public static final int appname0x7f040001

...other entries depending on your project and application

...other entries depending on your project and application

Let's focus on the static definition for static final class string. creates this inner static class as a namespace to hold string-resource IDs. The two static final ints defined with variable names hello and app_name are the resource IDs that represent the corresponding string resources. You could use these resource IDs anywhere in the source code through the following code structure:


Note that these generated IDs point to ints rather than strings. Most methods that take strings also take these resource identifiers as inputs. Android will resolve those ints to strings where needed.

It is merely a convention that most sample applications define all strings in one strings. xml file. Android takes any number of arbitrary files as long as the structure of the XML file looks like Listing 3-1 and the file resides in the /res/values subdirectory.

The structure of this file is easy to follow. You have the root node of <resources> followed by one or more of its child elements of <string>. Each <string> element or node has a property called name that will end up as the id attribute in and the actual text for that string ID.

To see that multiple string-resource files are allowed in this subdirectory, you can place another file with the following content in the same subdirectory and call it strings1.xml:

<?xml version="1.0" encoding="utf-8"?> <resources>

<string name="hello1">hello 1</string> <string name="app_name1">hello appname 1</string> </resources>

The Eclipse ADT plug-in will validate the uniqueness of these IDs at compile time and place them in as two additional constants: R.string.hello1 and R.string.app_name1.

0 0

Post a comment