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. :)
You can also use
TimerTask
for that.Here is an method
If you want to show time on textview then better use Chronometer or TextClock
Using Chronometer:This was added in API 1. It has lot of option to customize it.
Your xml
Your activity
Using TestClock: This widget is introduced in API level 17.I personally like Chronometer.
Your xml
Thats it, you are done.
You can use any of this two widget. This will make your life easy.
You can use Timer instead of Thread. This is whole my code