倒计时器

时间:2011-03-08 06:18:51

标签: java

我想在倒数计时器结束后执行我的beginrecording()方法。但这两种方法都在同一时间执行。任何人都可以帮我解决这个问题。 我的代码如下:

StartBtn.setOnClickListener(new OnClickListener() {
            public void onClick(View view)
            { 
                //setContentView(textState);

                MyCount counter = new MyCount(6000, 1000, textState);


                StartBtn.setVisibility(4);
                counter.start();            


                    try
                    {
                    //  Thread.sleep(2000);
                        beginRecording();
                        EndBtn.setVisibility(0);

                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }                               
            }

        });

提前致谢

2 个答案:

答案 0 :(得分:0)

什么是MyCount?是Timer吗?

可能你应该尝试这样的事情

int i = 0;
Timer timer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
    if (i == 100){   //-------- When you want to stop timer and start your function
       timer.stop();
       try{
           //  Thread.sleep(2000);
           beginRecording();
           EndBtn.setVisibility(0);
       } catch(Exception e){
           e.printStackTrace();
       }    
    } 
    i = i + 1;
   }
});

timer.start();

希望这有帮助。

答案 1 :(得分:0)

我猜测MyCounter的计数器对象是Thread的子类。 所以你可以打电话:

counter.join();

之前打电话

beginRecording();

这可确保您的计数器在返回当前线程之前执行。