Using Resources

This section describes how to use the resources you've created. It includes the following topics:

• Using resources in code - How to call resources in your code to instantiate them.

• Referring to resources from other resources - You can reference resources from other resources. This lets you reuse common resource values inside resources.

• Supporting Alternate Resources for Alternate Configurations - You can specify different resources to load, depending on the language or display configuration of the host hardware.

At compile time, Android generates a class named R that contains resource identifiers to all the resources in your program. This class contains several subclasses, one for each type of resource supported by Android, and for which you provided a resource file. Each class contains one or more identifiers for the compiled resources, that you use in your code to load the resource. Here is a small resource file that contains string, layout (screens or parts of screens), and image resources.

Note: the R class is an auto-generated file and is not designed to be edited by hand. It will be automatically re-created as needed when the resources are updated.

package com.android.samples; public final class R {

public static final class string {

public static final int greeting=0x0204000e; public static final int start button text=0x02040001; public static final int submit button text=0x02040008; public static final int main screen title=0x0204000a;

public static final class layout {

public static final int start screen=0x02070000; public static final int new user pane=0x02070001; public static final int select_user_list=0x02070002;

public static final class drawable {

public static final int company logo=0x02020005; public static final int smiling cat=0x02020006; public static final int yellow fade background=0x02020007; public static final int stretch button 1=0x02020008;

0 0

Post a comment