我想我的程序在等待我,而10S真实的,但它不工作 我试图用Thread.sleep(10000);
但它不是10秒等待时间 - Android电子
while (true) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 5; j++) {
if (matrixVacancy[i][j] == 1) {
completeParking(i, j, R.color.vaga_ocupada);
} else {
completeParking(i, j, R.color.cor_chao);
}
}
}
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
}
int a, b, c, d, e, f, g, h, i;
a = (int) (Math.random() * 2); // indice i
b = (int) (Math.random() * 5); // indice j
c = (int) (Math.random() * 2); // tem ou nao carro
d = (int) (Math.random() * 2); // indice i
e = (int) (Math.random() * 5); // indice j
f = (int) (Math.random() * 2); // tem ou nao carro
g = (int) (Math.random() * 2); // indice i
h = (int) (Math.random() * 5); // indice j
i = (int) (Math.random() * 2); // tem ou nao carro
matrixVacancy[a][b] = c;
matrixVacancy[d][e] = f;
matrixVacancy[g][h] = i;
}
我该怎么办呢?对于我而言,等10秒?
什么时候你想让你的功能等待?请更多的背景。 – stealthjong
准确地说你是如何做到的。它怎么不起作用?如果您的应用停止响应一段时间,Android会提供您强制关闭它。也许你应该在单独的(非UI)线程上运行该循环? – nullpotent
尝试使用CountDownTimer或简单的计时器为此https://developer.android.com/reference/android/os/CountDownTimer.html https://developer.android.com/reference/java/util/Timer.html –