如何每3秒处理一次线程消息

时间:2017-03-14 05:26:32

标签: android multithreading handler

我是Android新手,我正在尝试使用线程构建一个读取语音信号值的应用程序,并使用处理程序在ui上显示值。 Recording thread that reads the values and sends message to handlerHandler for the recording thread message

我实际上需要textview每3秒更新一次,但变量值的值会更快地更新。在包含记录线程的代码中,我想在每3秒后发送一条消息(可以看出,while循环运行3秒)。但我无法做到这一点。请帮忙!!

2 个答案:

答案 0 :(得分:1)

您可以使用Handler类:

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

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

答案 1 :(得分:0)

使用处理程序或TextView:

textView.postDelay(new Runnable());
相关问题