我想使用的setContentView()方法的线程已经完成了他的任务后。 但是,我怎么能认识到这一点,因为它不能使用线程内这种方法吗? 当在onCreate()方法使用此方法的线程运行的同时,我也鸵鸟政策得到正确的结果,导致布局至极应该先“的setContentView(R.layout.load_screen)”不显示显示。
我的onCreate()方法:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Open loading screen
setContentView(R.layout.load_screen);
this.loadingScreen(); // In this method the new Thread will start.
}
我loadingScreen()方法:(线程完成后,我想使用的setContentView()再次)
public void loadingScreen(){
// prepare for a progress bar dialog
progressBar = new ProgressBar(this);
progressBar = (ProgressBar)findViewById(R.id.progressBar1);
//reset progress bar status
progressBarStatus = 0;
new Thread(new Runnable() {
public void run() {
while (progressBarStatus < 100) {
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// process some tasks
progressBarStatus = doSomeTasks();
// your computer is too fast, sleep 1 second
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Update the progress bar
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressBarStatus);
}
});
}
// ok, file is downloaded,
if (progressBarStatus >= 100) {
// sleep 2 seconds, so that you can see the 100%
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}