【问题标题】:what is wrong with this loop? - android studio这个循环有什么问题? - 安卓工作室
【发布时间】:2020-07-13 19:51:24
【问题描述】:

我编写此代码用于创建一个循环并将所有名称保存到一个数组中,但循环在第一次单击时结束,它使按钮为假,它必须在 10 个名称后使按钮为假,但它不起作用 如何编辑此代码?

int oyuncuSayisi = 0;
                for (int a = 0; a < 10; a++) {
                    isimGirisString = oyuncular[a];
                    oyuncuSayisi++;
                }
                if (oyuncuSayisi > 9) {
                    oyuncuKayit.setEnabled(false);

【问题讨论】:

  • if 语句放入 for 循环中。
  • 我试过了还是一样

标签: java android for-loop conditional-statements


【解决方案1】:

您不需要循环,它只是一个条件。试试这样的:

int counter=0; //init your variable somewhere

/*...


*/
@Override
public void OnClick(View v){
    conter++;
    isimGirisString = oyuncular[a];
    if(conter==10){
    //do your action here
    oyuncuKayit.setEnabled(false);
    }
}

然后它会一直运行,直到你点击按钮 9 次

【讨论】:

    猜你喜欢
    • 2017-07-30
    • 1970-01-01
    • 2016-03-03
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多