2017-03-14 25 views
0

我是新來的android和我試圖建立一個應用程序,讀取語音信號值使用線程和UI顯示值使用處理程序。 Recording thread that reads the values and sends message to handlerHandler for the recording thread message如何處理線程消息每3秒

我實際上需要textview每3秒更新一次,但變量值的更新速度非常快。在包含記錄線程的代碼中,我想每3秒發送一次消息(可以看出,while循環運行3秒)。但我無法做到這一點。請幫忙!!

+0

看看[這裏](http://stackoverflow.com/questions/21726055/android -loop部分的最碼-每-5-秒) – Redman

回答

1

可以使用Handler類:

final Handler handler = new Handler(); 
handler.post(new Runnable(){ 

    @Override 
    public void run(){ 
     // change your text here 
     handler.postDelayed(this, 3*1000); 
    } 
}); 
0

使用處理器或TextView的:

textView.postDelay(new Runnable());