package gr.mybook.mythreadpost;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

public class Activity_1 extends Activity {
	TextView text1, text2;
	//new handler
	Handler handler = new Handler();
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_1);
        text1 = (TextView) findViewById(R.id.textView1);
        text2 = (TextView) findViewById(R.id.textView2);
    }
    
    @Override
    protected void onStart() {
     super.onStart();
	 final int[] i = new int[1];
	 // new thread
	 new Thread() {
           public void run() {
                      for (i[0]=0; i[0] < 10; i[0]++) {
                            try {
                                Thread.sleep(1000);
                                    handler.post(new Runnable() {
                                    	public void run() {
                                            text1.setText("POST MESSAGE:  " + String.valueOf(i[0]));
                                        }    
                                    });
                                    handler.post(new Runnable() {
                                        public void run() {
                                            text2.setText("POST MESSAGE:  " + String.valueOf(9-i[0]));
                                        }    
                                    });
                            }catch (InterruptedException e) {
                          	e.printStackTrace();
                            }
                      }
                  }
        }.start();
    }
}