2017-03-14 28 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());