我使用调试器来发现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;
}
答案 0 :(得分:1)
townHallLvl = add(townHallLvl);
您可能错过了将值分配给townHallLvl。