提问人:Rose 提问时间:11/5/2022 更新时间:11/5/2022 访问量:31
我可以使用某种循环来更改重复(略有不同)的变量吗?
Can I use some sort of loop to change repeating (slightly differing) variables?
问:
这是我当前的代码,无论如何我都可以使用某种循环来替换复制粘贴吗?我是 如果这有什么不同,请使用 Android Studio。
if (otterPurchased >= 1) {
TableRow layoutOtter2 = (TableRow) findViewById(R.id.layoutOtter2);
layoutOtter2.setVisibility(View.VISIBLE);
if (otterPurchased >= 2) {
TableRow layoutOtter3 = (TableRow) findViewById(R.id.layoutOtter3);
layoutOtter3.setVisibility(View.VISIBLE);
if (otterPurchased >= 3) {
TableRow layoutOtter4 = (TableRow) findViewById(R.id.layoutOtter4);
layoutOtter4.setVisibility(View.VISIBLE);
if (otterPurchased >= 4) {
TableRow layoutOtter5 = (TableRow) findViewById(R.id.layoutOtter5);
layoutOtter5.setVisibility(View.VISIBLE);
if (otterPurchased >= 5) {
TableRow layoutOtter6 = (TableRow) findViewById(R.id.layoutOtter6);
layoutOtter6.setVisibility(View.VISIBLE);
if (otterPurchased >= 6) {
TableRow layoutOtter7 = (TableRow) findViewById(R.id.layoutOtter7);
layoutOtter7.setVisibility(View.VISIBLE);
if (otterPurchased >= 7) {
TableRow layoutOtter8 = (TableRow) findViewById(R.id.layoutOtter8);
layoutOtter8.setVisibility(View.VISIBLE);
if (otterPurchased >= 8) {
TableRow layoutOtter9 = (TableRow) findViewById(R.id.layoutOtter9);
layoutOtter9.setVisibility(View.VISIBLE);
if (otterPurchased >= 9) {
TableRow layoutOtter10 = (TableRow)
findViewById(R.id.layoutOtter10);
layoutOtter10.setVisibility(View.VISIBLE);
if (otterPurchased >= 10) {
TableRow layoutOtter11 = (TableRow) findViewById(R.id.layoutOtter11);
layoutOtter11.setVisibility(View.VISIBLE);
}
}
}
}
}
}
}
}
}
}
}
这只会检查变量,如果为 true,则运行下面的代码,也是在永久循环中。
答: 暂无答案
评论