• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Chronometer help

The code I have so far is:

Code:
import android.app.Activity;
import android.os.Bundle;
import android.widget.Chronometer;
import android.widget.Chronometer.OnChronometerTickListener;
import android.widget.TextView;
import android.os.SystemClock;

public class Test extends Activity {
	
	TextView textGoesHere;
    long startTime;
    long countUp;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        
        Chronometer stopWatch = (Chronometer) findViewById(R.id.chrono);
        startTime = SystemClock.elapsedRealtime();

        textGoesHere = (TextView) findViewById(R.id.textGoesHere);
        stopWatch.setOnChronometerTickListener(new OnChronometerTickListener(){
            @Override
            public void onChronometerTick(Chronometer arg0) {
                countUp = (SystemClock.elapsedRealtime() - arg0.getBase()) / 1000;
                String asText = (countUp / 60) + ":" + (countUp % 60); 
                textGoesHere.setText(asText);
            }
        });
        stopWatch.start();
    }
}

There is a red 'x' by this line:

Code:
 textGoesHere = (TextView) findViewById(R.id.textGoesHere);

I'm not sure what I am meant to do to rectify it. Quite new to this so any pointers would be great. The page this code is on loads but the timer doesn't start.
 
Back
Top Bottom