所以我实现了一个调用timeTask扩展名的计时器,名为labelsTimer。该方法应该将文本的标签更改为代码中规定的标签,而是抛出错误
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
这是代码
public class labelsTimer extends TimerTask {
EditText label;
labelsTimer(EditText label)
{ super();
this.label = label;
}
@Override
public void run()
{
System.out.print("fsdfsd");
label.setText("hehehehe");
}
}
答案 0 :(得分:1)
使用此
public void run(){
runOnUiThread(new Runnable() {
@Override
public void run() {
label.setText("hehehehe");
}
});
}
答案 1 :(得分:0)
更改此包装线程中的标签
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
label.setText("hehehehe");
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}