我使用调试器发现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;
    }

最佳答案

townHallLvl = add(townHallLvl);


您可能错过了将值分配回townHallLvl的机会。

08-06 08:40