变量的机器人全局声明全局、变量、机器人、声明

2023-09-05 07:45:35 作者:硬汉洞庭一翻舟

我是新android开发,我解析通过SAX解析器一个XML文件,并存储数据解析到一个string.Now我需要使用该字符串在另一个类,所以我需要知道如何调用该解析器新类。  在此先感谢

I am new to android development, I am parsing a xml file through SAX parser and storing the parsed data into a string.Now i need to use that string in another class, so i need to know how to call that parser in the new class. thanks in advance

推荐答案

我总是包含了我所有的全局一类,并把它称为Constants.java

I always make a class that contains all of my globals and call it "Constants.java"

final public class Constants//final to prevent instantiation
{
    public static final String SOME_STRING = "0.04";
    public static final int SOME_NUMBER = 5;
    public static final float METERS_PER_MILE = 1609.344f;

    //private constructor to prevent instantiation/inheritance
    private Constants()
    {
    }
}

要使用其中的一个在code,一定要导入类和使用:

to use one of these in your code, be sure to import the class and use:

Constants.SOME_NUMBER

Constants.SOME_NUMBER