It is necessary that immediately after clicking the text appeared, and in a second the execution would continue. In fact, everything goes wrong - the delay is triggered before the appearance of the inscription.

public void onClick(View v) { switch (v.getId()) { case 1: tvOutAns.setTextColor(colorGreen); tvOutAns.setText("правильно: " + answer); try { TimeUnit.MILLISECONDS.sleep(1000); } catch (Exception e) { } createTask(); break; } } 
  • and you put 10,000 and check, it seems to you or still not - rjhdby
  • A checked text appears after ten seconds. - lmihael
  • TimeUnit.SECONDS.sleep (x) calls Thread.sleep, i.e. "freezes" thread. Accordingly, you gave the command to install a new text, it started to move the guem there, and here you are with him! Stand afraid! - rjhdby
  • Thank. Clear. And what to do? - lmihael
  • Run a cycle for him for a little longer and put a delay there? But this is somehow inhumane :) - lmihael

1 answer 1

For example, you can

 Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { // код, который надо запустить через секунду } }, 1000); 

Or in fashionable lambdas (I recommend by the way, google retrolambda)

 (new Handler()).postDelayed(()->{/*код*/},1000); 
  • Thank! And for an explanation and advice! - lmihael