变量的机器人全局声明 [英] Global declaration of variable in android

查看:140
本文介绍了变量的机器人全局声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新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

这篇关于变量的机器人全局声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆