Java Android变量的值不会更新

时间:2016-06-01 13:14:09

标签: java android android-studio

我使用调试器来发现townHallLvl的值在结尾处保持为1

请帮忙

int townHallLvl = 1;


public void addTownHall(View v){
        if (townHallLvl == 11) {
            Toast.makeText(this, "You can't have more than Town Hall lvl 11!!!", Toast.LENGTH_SHORT).show();
            return;
        }
        add(townHallLvl);
        TextView townHallText = (TextView) findViewById(R.id.town_hall_lvl);
        townHallText.setText(String.valueOf(townHallLvl));
    }




public int add(int lvl){
            int ans = lvl + 1;
            return ans;
    }

1 个答案:

答案 0 :(得分:1)

townHallLvl = add(townHallLvl);

您可能错过了将值分配给townHallLvl。