I need to display two timers on my app, I have two approaches, one is to implement the displays as TextView and then use java.util.Timer and TimerTask to update its text, however, the text doesn't redraw itself after update. The other approach is to use DigitalClock, but I can't find a way to directly start/stop the clock. see code below.
please help. thanks! class DisplayTimerTask extends TimerTask{ DateFormat dateFormat =new SimpleDateFormat("HH:mm:ss MM/dd/ yyyy"); private TextView display; public DisplayTimerTask(TextView display){ this.display=display; } public void run() { String time = dateFormat.format(new Date()); display.setText(time); display.invalidate(); System.err.println("set time to "+time); } } protected void stopTimer() { Button stopButton = getStopButton(); stopButton.setEnabled(false); getStartButton().setEnabled(true); if(stopDisplayTimer!=null)stopDisplayTimer.cancel(); stopDisplayTimer = new Timer(); stopDisplayTimer.schedule(new DisplayTimerTask(getStopTimeLabel()), 0, 500); /* DigitalClock clock=(DigitalClock)findViewById(R.id.clock); clock.setEnabled(false); */ } protected void startTimer() { Button startButton=getStartButton(); startButton.setEnabled(false); getStopButton().setEnabled(true); if(startDisplayTimer!=null)startDisplayTimer.cancel(); startDisplayTimer = new Timer(); startDisplayTimer.schedule(new DisplayTimerTask(getStartTimeLabel ()), 0, 500); /* DigitalClock clock=(DigitalClock)findViewById(R.id.clock); clock.setEnabled(true); */ } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---