我有一个计时器,我希望它从用户单击按钮时开始计数,而不是从活动开始时开始计数。目前,当用户单击按钮从 0 开始计时器时,它只显示从 Activity 开始的时间。以下是相关代码:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.startTimer: {
Chronometer stopWatch = (Chronometer) findViewById(R.id.chrono);
startTime = SystemClock.elapsedRealtime();
timer = (TextView) findViewById(R.id.timerText);
stopWatch.setOnChronometerTickListener(new OnChronometerTickListener(){
@Override
public void onChronometerTick(Chronometer arg0) {
countUp = (SystemClock.elapsedRealtime() - arg0.getBase()) / 1000;
String asText = (countUp / 60) + ":" + (String.format("%02d", (countUp % 60)));
timer.setText(asText);
}
});
stopWatch.start();
break;
}
...
我需要改变什么?