5

When I start the chronometer from another class with the start() function. It doesn't seem to be starting. It always gives me the beginning value "00:00" and nothing more.

 public class Kronometre {
    Context context;
    long countUp;
    Chronometer stopWatch;
    String asText = "00.00";

    public Kronometre(Context context) {
        this.context = context;
        stopWatch = new Chronometer(context);
    }

    public void start() {
        stopWatch.setOnChronometerTickListener(new OnChronometerTickListener(){
            @Override
            public void onChronometerTick(Chronometer arg0) {
                countUp = (SystemClock.elapsedRealtime() - arg0.getBase()) / 1000;
                asText = (countUp / 60) + "." + (countUp % 60);
            }
        });
        stopWatch.start();
    }

    public String getTime() {
        return asText;
    }
}
iCould7
  • 635
  • 6
  • 10
  • add `Chronometer` in `setContentView()` or add `Chronometer` to a activity's visible parent layout.. – CRUSADER Jul 03 '13 at 07:17
  • I really didn't understand man. What is activity's visible parent layout? Could you be more explanatory. – iCould7 Jul 03 '13 at 07:26
  • Suppose you have `setContentView(myLinearLay);` then you have to add `myLinearLay.add(stopWatch )` before setcontentView where `stopWatch` is your chronometer object – CRUSADER Jul 03 '13 at 07:31
  • Sorry man still dont get it. I am using a surfaceView and it doesn't have an add() function. – iCould7 Jul 03 '13 at 08:30

0 Answers0