There are two methods. The main one is initializeGame ():

public void initializeGame() { new Thread(new onePoint()).start(); try { Thread.sleep(6000); } catch (InterruptedException e) { e.printStackTrace(); } } } 

You can see that it launches a new stream, described in the onePoint class:

 class onePoint implements Runnable { (...) public void run() { (...) while (...) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } (...) if (...) { setOpacityOnButton(...); } } } 

So here. The initializeGame method starts by pressing the start button. The additional flow is created, the mechanical work with the variables in this additional flow is normal. However, the graphical representation does not change (I call this change by calling the setOpacityOnButton () method) until the main thread ends (that is, it takes about 6 seconds). Why it happens? Certainly not because of if (checked). Just in case this is the setOpacityOnButton () method:

 void setOpacityOnButton(int id, final int opacity) { final Button btn = (Button) findViewById(id); runOnUiThread(new Runnable() { @Override public void run() { if (opacity != 0) { btn.setText(Integer.toString(opacity)); } else { btn.setText(""); } } }); } 
  • Show how you call initializeGame() ? It seems to me that you call Thread.sleep() directly in the UI thread, and then you try to change the text on the button in it. - zRrr
  • initializeGame () is called by clicking on the start button (the most common view element). - DeathCookies
  • Your graphical representation does not change, since you are forced to sleep for 6 seconds - Android Android
  • So I put to sleep not the stream in which this view changes. - DeathCookies
  • @DeathCookies, if initializeGame is called from onClick, then you slow down the UI thread, so everything that is executed in runOnUiThread waits for these 6 seconds. - ravikwow

1 answer 1

The problem was solved, gentlemen. It was wrong to call the Thread.sleep () method in the main thread, since it is through it that the ui change occurs, i.e. graphic representation of the program.

  • those. need to put a construction with the Thread.sleep () method into a new thread - DeathCookies
  • that's exactly what everyone wrote to you. - ravikwow