title: Display values in ArrayList one by one in textView
body: <p>I am trying to display values inside ArrayList on single line textView one by one after some interval. How to achieve this without blocking the main thread?</p>
  
  <p>I have written code which is able to do this with Thread.sleep but, after a few seconds of running, activity is getting crashed. I have used For Loop &amp; Thread.sleep to iterate every ArrayList value after some interval. </p>
  
  <p>When activity crashes, I am getting <code>IndexOutOfBondException</code> after a few seconds of running. </p>
  
  <pre><code>public void errorRepeater() {
  
      Thread t = new Thread() {
  
          @Override
          public void run() {
              //  !isInterrupted()
  
              while (!isInterrupted()) {
                  for (xz = 0; xz &lt; errorList.size(); xz++) {
                      try {
                          Thread.sleep(2000);  //1000ms = 1 sec
  
                          runOnUiThread(new Runnable() {
  
                              @Override
                              public void run() {
                                  String sErrorList = errorList.get(xz);
                                  String sErrorListOkBox = errorListOkBox.get(xz);
                                  Log.i("MQTT sErrorList", sErrorList);
                                  TextView tvC1HPLP = findViewById(R.id.errormsg);
                                  tvC1HPLP.setText(sErrorList);
                                  TextView tvok = findViewById(R.id.ok);
                                  tvok.setText(sErrorListOkBox);
                                  rl.setBackgroundResource(R.drawable.errorred);
                                  tvC1HPLP.setTextColor(Color.RED);
  
                              }
                          });
  
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
                  }
              }
          }
      };
  
      t.start();
  
  }
  </code></pre>
  
  <p>textView should display values inside ArrayList one by one without crashing activity.</p>