2014-10-09 74 views
0

在這段代碼中,我想讓for循環延遲700毫秒,我該如何實現它。在這段代碼中,循環完成了700毫秒延遲的bez,但是我想讓for循環的每次迭代延遲700毫秒。更多的疑問是我不應該在UI線程上使用Thread.sleep();使循環延遲一段時間

for(int i=0;i<Uirkeys.length;i++){ 
    Handler handler=new Handler(); 
    handler.postDelayed(new Runnable(){ 
    @Override 
    public void run() { 
     copyView.get(cnt1).setBackgroundColor(Color.BLACK); 
     TeaxtToSpeach(map.get(Uirkeys[cnt1])); 
     cnt1++; 
     } 
    },700); 
} 
+0

使用AsyncTask來執行循環。然後你可以使用Thread.sleep() – 2014-10-09 14:09:14

回答

0

請嘗試以下代碼。

try{ 

Thread.sleep(1000); 
}catch(InterruptedException ex){ 
//do stuff 
}