Code example for Chronometer

Methods: setBase, setFormat, start

0
		startbutton.setOnClickListener(new View.OnClickListener() {
 
			@Override 
			public void onClick(View v) {
				// chronometer.setBaseTime(System.currentTimeMillis()); 
				chronometer.setFormat("%s");
				if (bStarted == false) {
					//load settings 
					getScreenoffPref(); 
					getYellowTimePref(); 
					getRedTimePref(); 
					//start timer 
					chronometer.setBase(SystemClock.elapsedRealtime()); 
					chronometer.start();
					bStarted = true;
					getWindow().addFlags(
							WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
					// 
					startbutton.setText("STOP");
					layoutRest.setBackgroundColor(Color.GREEN);
					upbutton.setTextColor(Color.GRAY);