how would i go about working out the elapsed time between button1 onClick and button2 onClick.
this is what i have written but it doesnt work, just prints current time.
start = (Button) findViewById(R.id.start);
start.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
private long startTime = System.currentTimeMillis();
}
});
stop = (Button) findViewById(R.id.stop);
stop.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
final long endTime = System.currentTimeMillis();
final long elapsedTime = endTime - startTime;
final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
BufferedWriter out = new BufferedWriter(new FileWriter("/sdcard/timer.txt", true));
out.write("Elapsed time:" + dateFormat.format(new Date(elapsedTime)));
out.write("\r\n");
out.close();
} catch (Exception e) {
}
}
});
any help would be greatful as i am at a loss
many thanks
This should work.
}