我有2个片段,其中一个我试图更新一些数据更新后的一些意见。当我有这些意见时,我保持分段时,我的意见更新得很好。更改为另一个片段后,我的线程继续正常工作。 但是,在我返回第一个片段后,我的视图无法更新。片段更改后无法更新视图
myThread = new Thread(){
@Override
public synchronized void run(){
while(true){
try {
sleep(2000);
myActivity.runOnUiThread(new Runnable(){
@Override
public void run(){
updateViews();
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
这是更新功能:
private void updateViews(){
textView.setText(_chronometerService.getTime());
}
通知我的线程不断更新的数据,我的问题是,为什么观点无法更新。
你为什么使用这样的线程? – Stefan
@Stefan只是为了更新我的观点。有另一种方法吗? – learner
处理程序,例如:http://stackoverflow.com/questions/6964011/handler-vs-asynctask-vs-thread – Stefan