0

I am just learning and exercising @ Android, and I tried to make a TextView display the current time, meaning the TextView gets updated every second. Now I know there are probably loads of better ways - Calendar's, DigitalClocks and other widgets to do this properly, but as I said, I am merely training.

My problem is that my "schedule" is not working... or I so I believe. I have a simple XML layout. Here is my Java code:

public void onClick(View v) 
 {
  View parent = (View) v.getParent();
  final Time tm = new Time();
  final TextView tv = (TextView) parent.findViewById(R.id.tv);
  Timer timer = new Timer();
  TimerTask tt = new TimerTask() {

   @Override
   public void run() {

    tm.setToNow();
    tv.setText(time.hour + ":" + time.minute + ":" + time.second);
   }
  };
  timer.scheduleAtFixedRate(tt, 0, 1000);

 }
George
  • 3,727
  • 9
  • 31
  • 47

1 Answers1

0

use handler to pass the time change to the textview..see:

how to change text in Android TextView

You have the right idea just need to wire timer to handler

Community
  • 1
  • 1
Fred Grott
  • 3,505
  • 1
  • 23
  • 18