how to update textview using thread?
<p>I am trying to update a textview after 3 seconds, and i want to do that in a loop for which i am using thread .....what should i do in order to start background thread so that exactly after 3 seconds background1 thread starts ... and it should be done in a loop ?</p>

<pre><code>     package com.edu.math;
    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.util.Log;
    import android.widget.TextView;

    public class EduMath extends Activity {
        TextView txt;
        TextView tv;
        TextView num;
        String x;
        int time = 3000;
        float z ;


    int random;
            int random1;
            int random_operator =1;

    /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            txt=(TextView)findViewById(R.id.txt);
            tv = (TextView)findViewById(R.id.randomNumber);

            background.start();
        }

        // our handler
        Handler handler = new Handler() {
        public void handleMessage(Message msg) {//display each item in a single line

            random = (int)Math.ceil(Math.random()*10);
            random1 = (int)Math.ceil(Math.random()*10);

            if(random1&gt;random)
            {
                txt.setText(/*txt.getText()+*/""+random1+" "+&gt;+" "+random+" "+
System.getProperty("line.separator"));
            }
            else
            {
                txt.setText(/*txt.getText()+*/""+random+" "+&gt;+" "+random1+
System.getProperty("line.separator"));
            }
        }
    };

    Handler handler1 = new Handler() {
        @Override
        public void handleMessage(Message msg) {//display each item in a single line


                txt.setText(/*txt.getText()+*/""+random1+" "+x+" "+random+System.getProperty("line.separator"));

        }
    };
    Thread background1 =new Thread(new Runnable() {

        @Override
        public void run() {

            for(int i=0;i&lt;10;i++)
            {
                try {

                    Thread.sleep(time);
                    // send message to the handler with the current message handler          

                    handler1.sendMessage(handler1.obtainMessage());
                    background.stop();
                    Log.d("EduMath-enclosing_method", "thread started");
                } catch (Exception e) {
                    Log.v("Error", e.toString());
                }
            }

        }
    });


    Thread background=new Thread(new Runnable() {

        @Override
        public void run() {
            for(int i=0;i&lt;10;i++)
            {
                try {
                    Thread.sleep(time);

        // send message to the handler with the current message handler          
                    handler.sendMessage(handler.obtainMessage());
                                        background1.start();
                } catch (Exception e) {
                    Log.v("Error", e.toString());
                }
            }
             }
    });
}
</code></pre>
