Note Each file in the reslayout subdirectory generates a unique constant based on the name of the file extension excluded With layouts what matters is the number of files with string resources what matters is the number of individual string resources insi

For example, if you have two files under /res/layout/ called file1.xml and file2.xml, you'll have the following entries in

public static final class layout {

____ any other files public static final int file1=0x7f030000; public static final int file2=0x7f030001;

The views defined in these layout files are accessible in code if you reference their IDs from

TextView tv = (TextView)this.findViewById(; tv.setText("Try this text instead");

In this example, you locate the TextView by using the findViewById method of the Activity class. The constant corresponds to the ID defined for the TextView. The id for the TextView in the layout file is as follows:

<TextView android:id="@+id/text1" </TextView>

chapter 3 ■ using resources, content providers, and intents

The attribute value for the id attribute indicates that a constant called text1 will be used to uniquely identify this view among other views hosted by that activity. The plus sign (+) in @+id/text1 means that text1 will be created if it doesn't exist already. There is more to this syntax, in which ids are assigned to resources. We'll talk about that next.

0 0

Post a comment