Code example for Chronometer

Methods: setOnChronometerTickListener, stop

0
         
        stopButton = (Button)findViewById(R.id.stop);
        stopButton.setOnClickListener(new Button.OnClickListener() {
        	@Override 
        	public void onClick(View view) {
        		chrono.stop();
        		clearChronoTickListener(); 
        	} 
        }); 
         
        resetButton = (Button)findViewById(R.id.reset);
        resetButton.setOnClickListener(new Button.OnClickListener() {
        	@Override 
        	public void onClick(View view) {
        		chrono.setBase(SystemClock.elapsedRealtime());
        		clearChronoTickListener(); 
        	} 
        }); 
         
        remainingTime = (TextView)findViewById(R.id.remaining_time);
        remainingTime.setText("Remaining time : ");
         
         
        tts = new TextToSpeech(getApplicationContext(), new OnInitListener() {
        	@Override 
        	public void onInit(int status) {
        		if(status == TextToSpeech.SUCCESS) {
        			readyToSpeak = true;
        		} 
        	} 
        }); 
    } 
     
    public void speakAndHear(String textToSpeak, long sleepTime, boolean startSpeechRecognition) {
    	comment.setText(textToSpeak);
    	if(readyToSpeak) {
    		clearChronoTickListener();    		 
    		Toast.makeText(this, "Speaking...", 5000).show();
    		tts.speak(textToSpeak, TextToSpeech.QUEUE_FLUSH, null);
    		if (startSpeechRecognition) {
				sleep(4500); 
				startVoiceRecognition(); 
			} 
    	} else { 
    		Toast.makeText(this, "Speech2Text not ready", 3000);
    	} 
    } 
     
    @Override 
    public void onDestroy() { 
    	super.onDestroy(); 
    	try { 
			if(tts != null) {
				tts.shutdown();
				tts = null;
			} 
		} catch (Exception e) {
			Log.e(TAG, e.getMessage());
		} 
    } 
     
    public void clearChronoTickListener() { 
    	chrono.setOnChronometerTickListener(null);
    } 
     
    public void addChronoTickListener() { 
        chrono.setOnChronometerTickListener(new OnChronometerTickListener() {
        	long elapsedSeconds = 0;