0
我有一個CountDownTimer類設置倒計時,當用戶點擊某個按鈕時將開始倒計時。
這是包括CountDownTimer文字在CountDownTimer中不顯示字符串
public class play extends Activity implements View.OnClickListener{
private TapCountDownTimer countDownTimer;
private final long startTime = 10;
private final long interval = 1;
private TextView countdowntext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.play);
countDownTimer = new TapCountDownTimer(startTime, interval);
countdowntext = (TextView)findViewById(R.id.countdowntext);
countdowntext.setText(String.valueOf(startTime));
Button buttonstart = (Button)findViewById(R.id.stopbutton);
buttonstart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
countDownTimer.start();
}
});
Button buttonstop = (Button)findViewById(R.id.stopbutton);
buttonstop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
countDownTimer.cancel();
}
});
public class TapCountDownTimer extends CountDownTimer {
public TapCountDownTimer(long startTime, long interval)
{
super(startTime, interval);
}
@Override
public void onTick(long millisUntilFinished)
{
countdowntext.setText(Long.toString(millisUntilFinished/1));
}
@Override
public void onFinish()
{
countdowntext.setText("Time's up!");
}
}
}
我設置文本在此行
countdowntext.setText(Long.toString(millisUntilFinished/1));
的代碼,但它不工作,文本顯示,而不是倒計時「時間到」。
有誰知道如何解決這個問題?
也許這是因爲'interval'設置爲'1' – Titus
@ FrankN.Stein好吧我會改變 – RichFounders