的setText是不是一个while循环中工作 [英] setText is not working inside a while loop

查看:379
本文介绍了的setText是不是一个while循环中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是为什么?

while (flag) {
outCPU.setText(getCpuInfo());
}

getCpuInfo返回字符串,如果我尝试写这个方法的返回伸到日志,也应该是一切,但没有任何反应到TextView的..

getCpuInfo returns string, if I try to write this method's return out into a log, there is everything that should be, but nothing happens to textview..

推荐答案

这将无法正常工作......你的函数结束后显示屏会更新。
试试这个

It will not work... display will update after your function finishes. Try this

boolean flag;
private void updateTextView(){
     outCPU.setText(getCpuInfo());
     if(flag){
         outCPU.post(new Runnable(){
             public void run(){
                 updateTextView();
             }
         });
     }
}

private void your_function(){
    if(flag){
         outCPU.post(new Runnable(){
             public void run(){
                 updateTextView();
             }
         });
     }

}

这篇关于的setText是不是一个while循环中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆