2012-04-10 62 views
0

我有一段时间后才开始的活动。一旦这个活动开始,用户应该按下一个按钮来启动一个新的计时器。使用CountDownTimer直到显示按钮被按下为止

但是,如果用户没有按下按钮,我想每5秒显示一次烤面包,直到按下按钮。

我正在尝试使用CountDownTimer。以下是我目前使用的代码的基础知识:

我没有错误,但目前没有任何敬酒。可以在BreakActivity类中使用MyCount类(如果我把它放在外面,我会得到一个错误)。

获得此排序的任何帮助将不胜感激!

public class BreakActivity extends Activity { 

Button startBreakButton; // button to start the break timer 
Boolean clicked= false; 
CountDownTimer counter; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.breakscreen); // sets layout to breakscreen.xml 

    MyCount counter; 
    counter=new MyCount(5000,1000); 
    counter.start(); 

    startBreakButton = (Button) findViewById(R.id.startBreakButton); 
    startBreakButton.setOnClickListener(mStartListener); 

    View.OnClickListener mStartListener = new OnClickListener() { 

clicked=true; 
//other listener code 
}; 

public class MyCount extends CountDownTimer{ 
    public MyCount(long millisInFuture, long countDownInterval) { 
    super(millisInFuture, countDownInterval); 
    } 
    @Override 
    public void onFinish() { 
     if(clicked=false){ 
     Toast.makeText(getApplicationContext(), "TAKE A BREAK", Toast.LENGTH_LONG).show(); 
     counter= new MyCount(5000,1000); 
    counter.start(); 
     } 

    } 
    @Override 
    public void onTick(long millisUntilFinished) { 
     long s1 = millisUntilFinished; 

    } 
    } 
    }; 

回答

1

变化:

if(clicked=false) 

if(clicked==false) 
+0

嗯,这是尴尬.... 感谢现在的工作! – Rob 2012-04-10 13:00:51

相关问题