可能重复:
CountDownTimer- 用户递增。问题
我必须制作一个应用程序,允许用户每次单击按钮将时间增加 +1。然后在按钮停止单击后等待三秒钟,然后开始倒计时。
我一直很困惑,然后意识到我可以通过一个 java 动作侦听器来实现这一点,我在其中使用了类似的东西。我发布了我的代码,但这不能正常工作 - 只是想知道是否有人可以引导我走向正确的方向。
谢谢
@SuppressWarnings("unused")
public class MainActivity extends Activity {
private static String TAG = "cs313f12p1a";
Button stoptime;
public TextView timedisplay;
public myTimer wavetimer;
private long millisInFuture;
private long millisUntilFinished;
private long countDownInterval;
private long onclicktime;
private WaveInterface model;
public long counter;
private boolean buttonClicked;
private Thread thread;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
stoptime = (Button) findViewById(R.id.button2);
stoptime.setText("Stop Timer");
timedisplay = (TextView) findViewById(R.id.mycounter);
timedisplay.setText("Time Left: " + millisUntilFinished);
wavetimer = new myTimer (millisInFuture, countDownInterval);
counter = 01;
final MainActivity MainActivity = this;
stoptime.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
if (!buttonClicked){
counter++;
} else {
wavetimer.start();
}
}
}});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}