title: How to update TextView dynamically (periodically)?
body: <p>I am developing a simple android activity with a scrollable <code>TextView</code>. I am displaying numbers from 1-100 in my <code>TextView</code> with a time delay. However my desired output is not what I'm getting.</p>
  
  <p><strong>Current Output:</strong> 1 replaced by 2 replaced by 3....till 100.<br>
  <strong>Desired Output:</strong><br>
                  1<br>
                  2<br>
                  3<br>
                  4<br>
                  .<br>
                  .<br>
                 100</p>
  
  <p>Here is my Activity code: </p>
  
  <pre><code>    public class MainActivity extends ActionBarActivity {
  
          private static int i = 0;
          TextView textView;
          Handler handler;
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main_page);
  
              textView = (TextView) findViewById(R.id.text_area);
              new PrimeCalculation().execute();
  
              handler = new Handler();
              handler.post(updateView);
         }
         private Runnable updateView = new Runnable() {
  
              @Override
              public void run() {
                  if(i &lt;= 100) {
                      textView.setText(Integer.toString(i));
                      i++;
                      handler.postDelayed(this, 1000);
                  }
              }
          }; 
      }
  </code></pre>