tags:

views:

22

answers:

1

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);

 }
A: 

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

http://stackoverflow.com/questions/2300169/how-to-change-text-in-android-textview

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

Fred Grott