安卓:从一个线程更新UI定期 [英] Android: Update UI periodically from a thread
本文介绍了安卓:从一个线程更新UI定期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
猜猜我有,我想在某些情况下更新它一个TextView。我想有每个一两秒钟检查的情况和更新,如果有必要的TextView的文本中的线程。
任何想法?
Guess that I have a TextView that I want to update it in some situations. I want to have a thread that every one or two seconds checks the circumstances and updates TextView's text if necessary. Any Idea?
推荐答案
您可以使用处理程序,在你的GUI:
You can use Handler, in your GUI:
Handler hnd = new Handler() {
public void handleMessage(Message msg) {
if ( msg.what == 101 ) {
//update textview
}
}
}
通HND你的线程,并在你的线程做的:
pass hnd to your thread, and in your thread do:
Message m = new Message();
m.what = 101;
hnd.sendMessage(m);
这是假定在单独的线程你正在做的,需要GUI线程汇报一些工作,也可以发短信
this assumes that in your separate thread you are doing some work that needs reporting to GUI thread, you can also send text messages
这篇关于安卓:从一个线程更新UI定期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文