我在Eclipse中计时器没有正常工作

编程入门 行业动态 更新时间:2024-10-10 15:23:27
本文介绍了我在Eclipse中计时器没有正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是新来的Eclipse和我在eclipse计时器没有正常工作,这是我的Java。 code。在定时器:

I am new to eclipse and my timer in eclipse did not work properly, this is my java. code in the timer:

Button countDownButton2 = (Button) findViewById(R.id.countDown1); countDownButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view){ CountDownTimer timer2 = new CountDownTimer(3000,1000){ @Override public void onFinish() { mTimeLabel1.setText("Times Up baby!"); } @Override public void onTick(long millisUntilFinished) { int seconds = (int) (millisUntilFinished / 1000); int minutes = seconds / 60; seconds = seconds % 60; mTimeLabel1.setText("" + minutes + ":" + String.format("%02d", seconds)); } }.start(); } });

基本上一切都运行如我所愿,但是,我发现,如果我点击触发按钮,而它计数,这将触发不停止previous计数另计。这是很尴尬的,我的朋友建议我做的开关,如果再按下此键触发,和我正在考虑到其他行动加入到同一个按钮是停止重新开始计数。哪一个更preferable?

Basically everything is running as I wish, however, I found that if I clicked the trigger button while it is counting, it will trigger another counting without stop the previous counting. This is very embarrassing, my friend suggest me to do "switch" if the button trigger again, and I am considering to add another actions to the same button which is stop the restart counting. Which one is more preferable?

推荐答案

禁用触发按钮。

这样,你将节省的痛苦fiqure如何做一个开关或之后,第一次点击添加其他操作的按钮。

That way you will save the pain to fiqure out how to do a switch or adding other actions to the button after the first click.

您可以尝试 yourbutton.setEnabled(假); 来使残疾人

如果我理解了code正确的,它应该是

if i have understood the code right, it should be

countDownButton2.setEnabled(假);

要再次启用按钮,使用

countDownButton2.setEnabled(真);

更多推荐

我在Eclipse中计时器没有正常工作

本文发布于:2023-11-06 08:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563212.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我在   计时器   工作   Eclipse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!