递增countDownTimer Android

递增countDownTimer Android,第1张

递增countDownTimer Android

您应该知道,

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;    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5142072.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存