I have a Chronometer. There should be the time displayed. When i start the timer the time is always the same, but it should update
Calling:
Log.e("XXX","OnClick");
String[] array = clock.getText().toString().split(":");
int ms = (Integer.valueOf(array[0])*60 + Integer.valueOf(array[1]))*60000;
Log.e("XXX",String.valueOf(ms));
MyTimer counter = new MyTimer(ms, 1000, Timer.this,clock);
counter.start();
Timer:
public class MyTimer extends CountDownTimer {
private Context con;
private Chronometer clock;
public MyTimer(long millisInFuture, long countDownInterval, Context context, Chronometer clock) {
super(millisInFuture, countDownInterval);
this.con = context;
this.clock= clock;
// TODO Auto-generated constructor stub
}
@Override
public void onTick(long millisUntilFinished) {
int seconds = (int) (millisUntilFinished / 1000) % 60 ;
int minutes = (int) ((millisUntilFinished / (1000*60)) % 60);
int hours = (int) ((millisUntilFinished / (1000*60*60)) % 24);
clock.setText( String.format("%02d:%02d:%02d", hours,minutes,seconds));
Log.e("Timer", String.valueOf(millisUntilFinished));
}
The problem is that the time in the chronometer is always the same. and the log(timer) also
don’t appear. Could it be that the refresh of the UI is too fast?
I’m not really confident with passing your context and view as an argument of your extended class. Maybe you should try this adaptation of your code (and get rid of your
MyTimerclass)?