I want to start a timer from 0th
second and for every 30 seconds,
I need to update the textview as 0.5min, 1.0min, 1.5min
etc.
How do I do this?
I want to start a timer from 0th
second and for every 30 seconds,
I need to update the textview as 0.5min, 1.0min, 1.5min
etc.
How do I do this?
Try this code,
final Handler h = new Handler();
h.post(new Runnable() {
@Override
public void run() {
long millis = (long) currentTime();
dateAndTime.setText(getDate(millis, "dd/MM/yyyy hh:mm:ss.SSS"));
h.postDelayed(this, 1000);
}
});
We can use an handler
to handle that.
You can define as below
Handler mHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
// write your code update textview
mHandler.sendEmptyMessageDelayed(0, 30000);
return true;
}
})
This handler will auto send and update the text again. You also need insert your code to update time for TextView.
Don't forget call the handler in the first time: mHandler.sendEmptyMessage(0);