我做了一个被称为每1秒和函数中我写为什么button.setText()显示错误
myButton.setText("Stop");
现在的一切,而不该代码的伟大工程的功能,但每当我写这篇文章的代码,移动我让我的测试显示消息“应用程序已停止工作” 我一直在寻找解决方案3天现在,帮助将不胜感激!
这是我的代码
check_time = new TimerTask() {
@Override
public void run() {
myButton.setText("Stop");
Calendar lo_Calender = Calendar.getInstance();
int current_h = lo_Calender.get(Calendar.HOUR);
int current_m = lo_Calender.get(Calendar.MINUTE);
if (H_toWake == current_h && M_toWake == current_m) {
out.println("ring");
alarm();
//return;
} else {
out.println("no ring!");
}
}
};
time.schedule(check_time, 0, 1000);
}
会试着告诉你;) –
对不起,但我应该使用包括定时函数还是(myButton.setText(“Stop”))到AsyncTasked类中? –
参考这个答案http://stackoverflow.com/questions/22890505/running-an-async-task-inside-a-timer-in-android – Helmi