Code example for Chronometer

Methods: setText, getBase

0
        timeView = (Chronometer)view.findViewById(R.id.interval_details_total_time);
        timeView.setOnChronometerTickListener(new OnChronometerTickListener(){
            @Override 
            public void onChronometerTick(Chronometer cArg) 
            { 
                long time = SystemClock.elapsedRealtime() - cArg.getBase();
                //dont let the timer get larger then 99h 59m 59s 
                if(356400000 + 3540000 + 59000 < time)
                { 
                    resetTimer(); 
                    return; 
                } 
                //TODO: go back to thread (or change chrono to have a shorter step) and implement 1/10 seconds 
                int h   = (int)(time/3600000);
                int m = (int)(time - h*3600000)/60000;
                int s= (int)(time - h*3600000- m*60000)/1000 ;
                String hh = h < 10 ? "0"+h: h+"";
                String mm = m < 10 ? "0"+m: m+"";
                String ss = s < 10 ? "0"+s: s+"";
                cArg.setText(hh+":"+mm+":"+ss);
            } 
        }); 
         
        runButton = (Button)view.findViewById(R.id.run_timer_button);
        runButton.setOnClickListener(runButtonClickListener);