title: Android studio Java update text in the loop
body: <p>first time learning coding language here..
  I am struggling in many parts of Java, but I am slowly learning.</p>
  
  <p>I was making an app and had to show dynamically updating text.
  So the below code is my attempt, it works very well (sort of).
  The problem is that it does not update the screen while program is running the for loop.</p>
  
  <p>So when I press a button from main activity, it runs an activity called play.
  It has 14 text fields of 0, and should update them to 7 one by one automatically.</p>
  
  <p>But after running the code below, it just shows fourteen 7s after a moment. (no 0s to start with too!)
  Any code for showing the screen so that I can put it under setText() ?</p>
  
  <p>I am sorry if this question was asked before but I really couldn't find any answer online.</p>
  
  <pre><code>public class Play extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      setContentView(R.layout.activity_play);
      Initialization();
  }
  
  public void Initialization() {
      TextView[] textViews = new TextView[] {
              (TextView)findViewById(R.id.player1_1),
              (TextView)findViewById(R.id.player1_2),
              (TextView)findViewById(R.id.player1_3),
              (TextView)findViewById(R.id.player1_4),
              (TextView)findViewById(R.id.player1_5),
              (TextView)findViewById(R.id.player1_6),
              (TextView)findViewById(R.id.player1_7),
  
              (TextView)findViewById(R.id.player2_1),
              (TextView)findViewById(R.id.player2_2),
              (TextView)findViewById(R.id.player2_3),
              (TextView)findViewById(R.id.player2_4),
              (TextView)findViewById(R.id.player2_5),
              (TextView)findViewById(R.id.player2_6),
              (TextView)findViewById(R.id.player2_7)
      };
      for (int i = 0; i &lt; 8; i++) {
          for (int j = 0; j &lt; 14; j++) {
              textViews[j].setText(Integer.toString(i));
              try {
                  Thread.sleep(25);
              } catch (InterruptedException ex) {
                  Thread.currentThread().interrupt();
              }
          }
      }
  }
  </code></pre>
  
  <p>}</p>