在安卓工作室循环(按钮)



>我有一个按钮,让用户在打开应用程序时可以使用该功能。

这是函数:

  if(eyeDected)
        {
            if(detectedFrame > 25)
            {
                eyeDected = false;
                detectedFrame = 0;
                finish();
            } else {
                detectedFrame++;
                Log.d("UNLOCK:", String.valueOf(detectedFrame));
            }
        } else {
            eyeDected = true;
            detectedFrame++;
            Log.d("UNLOCK:", String.valueOf(detectedFrame));
        }

我想做一个while循环函数:(点击次数为a,b,c)(例如b = 1表示用户仅点击一次)

a=0
b=1
c=2
when 'a' = 0,3,6,9,12,15..... (mean 'a'+3) then run the function
when 'b' = 1,4,7,10 ,13....(mean b+3) then run the function
when 'c' = 2,5,8,11,16... (mean b+3) then run the function

如何为这些执行 while 循环?谢谢

您可以添加以下条件:

a=0
b=1
c=2

当 'a' = 0,3,6,9,12 (平均值 'a'+3) 时,运行一个函数

if(a%3 == 0){
// run a function
}

当 'b' = 1,4,7,10(平均值 B+3)时,运行一个函数

if((b+1)%3 == 0){
// run B function
}

当 'c' = 2,5,8,11 (平均值 B+3) 时,运行一个函数

if((c+2)%3 == 0){
// run B function
}

例如在环:

for (int i=0;i<100;i++){
   if( i % 3 == 0){
      // run a function
   }
   else if( (i+1) % 3 == 0){
      // run b function
   }
   else if( (i+2) % 3 == 0){
      // run c function
   }
}

最新更新