我正在尝试为 android 制作一个秒表作为记分板应用程序的一部分问题是我不确定如何使用它chronometer to start, stop, then resume
从停止或重置为 0 的时间开始。唯一的问题是我不确定如何正确使用setBase()
和getBase()
方法。
public class MainActivity extends Activity {
int homecount, awaycount, minutes, seconds;
TextView home, away;
Button stop, start, reset, addhome, subhome, addaway, subaway;
TextView time;
public boolean running;
Chronometer MyChronometer;
long startTime, stopTime;
running = false;
stopTime = 0;
MyChronometer = (Chronometer) findViewById(R.id.timer);
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
((Chronometer) findViewById(R.id.timer)).start();
startTime=System.currentTimeMillis();
running = true;
}
});
stop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
((Chronometer) findViewById(R.id.timer)).stop();
stopTime=System.currentTimeMillis();
running = false;
}
});
reset.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
}
});