Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CountDownTimer t;
- t = new CountDownTimer( Long.MAX_VALUE , 1000) {
- @Override
- public void onTick(long millisUntilFinished) {
- cnt++;
- String time = new Integer(cnt).toString();
- long millis = cnt;
- int seconds = (int) (millis / 60);
- int minutes = seconds / 60;
- seconds = seconds % 60;
- txtcount.setText(String.format("%d:%02d:%02d", minutes, seconds,millis));
- }
- @Override
- public void onFinish() { }
- };
- textView = (TextView) view.findViewById(R.id.textView1);
- final Timer t = new Timer("hello", true);
- t.schedule(new TimerTask() {
- @Override
- public void run() {
- textView.post(new Runnable() {
- public void run() {
- seconds++;
- if (seconds == 60) {
- seconds = 0;
- minute++;
- }
- if (minute == 60) {
- minute = 0;
- hour++;
- }
- textView.setText(""
- + (hour > 9 ? hour : ("0" + hour)) + " : "
- + (minute > 9 ? minute : ("0" + minute))
- + " : "
- + (seconds > 9 ? seconds : "0" + seconds));
- }
- });
- }
- }, 1000, 1000);
- view.findViewById(R.id.stop).setOnClickListener(
- new OnClickListener() {
- public void onClick(View v) {
- t.cancel();
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement