mercredi 30 décembre 2015

How can I delay onClick action

I am trying to do something in java app (android) and I need something to delay/wait for an amount of seconds for a loop. How can I do delay android function? I have tried to use Thread.sleep(), TimeUnit.sleep, but it is only going to do irresponsible program for some seconds. I want to do some onClick actionlistener which updating for some seconds. e.g: if I clicked to button -> Text is changed to random(int) and it's should be done per second.

random ... waiting for a second ... random ... waiting for a second ... random ... and so many times

for (int i = 0; i < 10; i++) {
    int random = r.nextInt(100) - 10;
    String rand = Integer.toString(random);
    textView3.setText(rand);
    TimeUnit.SECONDS.sleep(1);
}




Aucun commentaire:

Enregistrer un commentaire