您应该知道,
onFinish倒计时类中的时间到了时不必手动调用,也不会
onFinish因为一个导致另一个而取消或手动递减任何东西。请尝试以下 *** 作,看它是否适合您要完成的任务。希望您能注意到,我没有看到一个实用的理由来查看按钮“是否不再被单击”。
public class MainActivity extends Activity { Button incrementTime, startTime; public TextView timedisplay; long millisInFuture = 1000; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); incrementTime = (Button) findViewById(R.id.button2); startTime = (Button) findViewById(R.id.button3); timedisplay = (TextView) findViewById(R.id.mycounter); resetText(); incrementTime.setonClickListener(new onClickListener() { public void onClick(View v) { millisInFuture += 1000; resetText(); } }); startTime.setonClickListener(new onClickListener(){ public void onClick(View v) { CountDownTimer wavetimer = new myTimer(millisInFuture + 3000, 1000).start(); // ^ add 3 seconds. } });} protected void resetText() { timedisplay.setText("Time Left: " + millisInFuture / 1000); } public class myTimer extends CountDownTimer { private long millisActual; public myTimer(long millisInFuture, long countDownInterval) { super(millisInFuture, countDownInterval); millisActual = millisInFuture - 3000; } @Override public void onTick(long millisUntilFinished) { //v start showing the tick after 3 seconds. if (millisUntilFinished <= millisActual) { timedisplay.setText("Time Left: " + millisUntilFinished / 1000); } } @Override public void onFinish() { timedisplay.setText("Countdown Finished"); } } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)