I've looked around and nothing seems to be working from what I've tried so far...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.deskclock);
TextView tvTime = (TextView) findViewById(R.id.tvTime);
TextView tvDate = (TextView) findViewById(R.id.tvDate);
java.util.Date noteTS = Calendar.getInstance().getTime();
String time = "hh:mm"; // 12:00
tvTime.setText(DateFormat.format(time, noteTS));
String date = "dd MMMMM yyyy"; // 01 January 2013
tvDate.setText(DateFormat.format(date, noteTS));
I basically want the setText methods to update or refresh every second or so, so my clock actually works like it should do. I've seen methods like handlers and run and nothing worked so any help with this would be great thanks. :)
Add following code in your onCreate() method:
This code starts an thread which sleeps 1000 milliseconds every round.
It would be better if you just used an AsyncTask running using a Timer something like this
Use
TextSwitcher
(for nice text transition animation) and timer instead.Extending @endian 's answer, you could use a thread and call a method to update the TextView. Below is some code I made up on the spot.
It's a very old question and I'm sure there are a lot of resources out there. But it's never too much to spread the word to be at the safe side. Currently, if someone else ever want to achieve what the OP asked, you can use:
android.widget.TextClock
.TextClock documentation here.
Here's what I've used:
This Code work for me..