2012-04-10 57 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

相關問題