【发布时间】:2010-11-02 10:47:44
【问题描述】:
我正在创建一个用于视频录制的应用程序,并在视频预览上添加了标签 txtStatus 和 txtTime。
相机按钮启动/停止定时调用UpdateGUI方法的定时器。运行调试,我可以看到计时器正在工作 - 它每秒调用 updateGUI 方法,但该方法不会更新控件。
如果我能得到有关如何解决此问题的任何提示,我将不胜感激。
代码如下:
这是激活定时器的方法:
private void startTimer()
{
updateTimer = new Timer("TimerUpdate");
updateTimer.scheduleAtFixedRate(new TimerTask(){
public void run(){
settings.IncreaseRecordingTime();
updateGUI();
}
}, 0, 1000);
}
这是 updateGUI 方法:
private void updateGUI()
{
setStatusLabel();
String strTime = settings.GetTimerString(); //strTime changes every second (it works as expected)
txtTimer.setText(strTime);//the text doesn't change!
}
这是按下按钮时调用的方法:
private boolean onCaptureButton()
{
settings.CaptureAction();
videoPreview.setFrameCallback(settings);
updateGUI();//here the function updateGUI() works as expected - it changes the txtStatus text from "Preview" to "Recording"
setTimer();
return false;
}
我还添加了一些 cmets(不知道为什么 updateGUI() 在 onCaptureButton() 方法中调用时有效,而在计时器方法中调用时无效)。
【问题讨论】:
标签: android user-interface timer