两个陈述中的时差

时间:2011-09-11 23:11:02

标签: java android multithreading

我想在连续语句之间给出1秒的时间差我知道多线程用于给出时间差。任何一个请帮助如何在执行两个语句时创建时差。

非常感谢!

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;

public class HelloActivity extends Activity {
       Canvas1[] can;
       Integer in[]={R.id.can1,R.id.can2,R.id.can3,R.id.can4,R.id.can5,
                       R.id.can6,R.id.can7,R.id.can8,R.id.can9,R.id.can10,
                       R.id.can11,R.id.can12,R.id.can13,R.id.can14,R.id.can15,R.id.can16};
   /** Called when the activity is first created. */
       Button start,stop;

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       start=(Button)findViewById(R.id.btn1);
       stop=(Button)findViewById(R.id.btn2);
       can=new Canvas1[16];
       for(int i=0;i<in.length;i++)
               can[i]=(Canvas1)findViewById(in[i]);
    for(int i=0;i<in.length;i++)
            can[i].set(0);
    //i want to make a time difference of 1 sec before control goes to the for loop

   }
}

1 个答案:

答案 0 :(得分:0)

any_view_in_your_activity.postDelayed(new Runnable(){public void run(){
    // Any code you write here will be run on UI thread after 1 second
}}, 1000);