title: How do I loop a piece of code in my main activity?
body: <p>I am using Android Studio and I wanted to loop this every half a second </p>
  
  <pre><code>"Random rand = new Random(); 
  int value = rand.nextInt(10);"
  </code></pre>
  
  <p>So anyway thanks for your time and if you can help that would be great. :)</p>
  
  <p>Sincerely,<br>
  Igor</p>
  
  <p>EDIT<br>
  Thanks everyone for the kind and helpful answers. I will choose the best answer soon after I try each one out. (Not with my computer right now) But once again, thank you all.
  Edit<br>
  For anyone having a similar problem I got it to work. Here is the final code.
  package sarju7.click;</p>
  
  <pre><code>import android.os.Handler;
  import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.TextView;
  
  import java.util.Random;
  
  
  public class MainActivity extends ActionBarActivity {
  
      Random rand = new Random();
      Handler handler = new Handler();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Runnable r = new Runnable() {
              public void run() {
                  int value = rand.nextInt(10);
                  TextView t1 = (TextView) findViewById(R.id.clicker);
                  t1.setText(Integer.toString(value));
                  handler.postDelayed(this, 400);
              }
          };
          handler.postDelayed(r, 400);
      }
  
      }
  </code></pre>
  
  <p>Once again thanks everyone. You guys are the best. I love all of stack overflow!</p>