为什么我的整数不是0而不是我在倒数计时器中设置的值?

时间:2014-10-04 19:19:31

标签: java android timer int

下面的代码中,我有一个名为ship1的整数,其值在倒计时器对象中设置为5。我想把这个int值放入一个字符串数组中,但是当我这样做时,当我将字符串数组的第一行打印到文本视图中时,ship1AddSpend(整数)变为零。为什么值不变为5?有人可以帮忙吗?

final TimerClass Timer2 = (TimerClass) new TimerClass(500,1000) {

    final public int OnFinish()
    {
        ship1AddSpend = 5;
        this.start();
        return ship1AddSpend;
    }

}.start();

int ship1AddSpend;

        final String[] shipDesc = {
                "10 Planets Every 5 Secs \n" + ship1AddSpend + "$",
                "50 Planets Every 5 Secs \n",
                "100 Planets Every 5 Secs \n 1500$",
                "500 Planets Every 4 Secs \n 3000$",
                "1000 Planets Every 4 Secs \n 7500$",
                "5000 Planets Every 4 Secs \n 15000$",
                "10000 Planets Every 3 Secs \n 50000$",
                "30000 Planets Every 3 Secs \n 100000$",
                "60000 Planets Every 3 Secs \n  500000$",
                "100000 Planets Every 1 Secs \n 1000000$"};

1 个答案:

答案 0 :(得分:0)

我从你的代码中理解的是你正在初始化字符串数组;特别是第0个位置的字符串,原始值为ship1AddSpend,为0.一旦字符串被初始化,它的值将永远不会改变,因为它是不可变的。

您可能想要做的是在您想要使用/显示所需变量的值时更改或准备字符串时准备字符串。使用StringBuffer动态准备字符串。希望这会有所帮助。