I tried to use Thread.sleep()
but it didn't work. When I use it, the app stops responding.
I need to put some delays in my code like this:
public void inicioJogo(){
for (int jogada = 1; jogada <= 50; jogada++) {
for (int contador = 0; contador < jogada; contador++){
// HERE - Wait 1 sec before go to next line.
btPedra[sequencia[contador]].setBackgroundResource(imagensHover[sequencia[contador]]);
// HERE - Wait 1 sec before go to next line.
btPedra[sequencia[contador]].setBackgroundResource(imagensNormal[sequencia[contador]]);
// Now continue looping.
}
}
}
I tried to use Handler, like this:
private Handler handler = new Handler();
for (int jogada = 1; jogada <= 50; jogada++) {
for (int contador = 0; contador < jogada; contador++){
handler.postDelayed(new Runnable () {
@Override
public void run() {
btPedra[sequencia[contador]].setBackgroundResource(imagensHover[sequencia[contador]]);
}
}, 1000);
}
}
But when I use it, the looping continue before waiting 1 sec. I need a delay that can stop the looping for 1 sec, go to the next line, and after that continue looping.