Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. CountDownTimer t;
  2.  
  3. t = new CountDownTimer( Long.MAX_VALUE , 1000) {
  4.  
  5. @Override
  6. public void onTick(long millisUntilFinished) {
  7.  
  8. cnt++;
  9. String time = new Integer(cnt).toString();
  10.  
  11. long millis = cnt;
  12. int seconds = (int) (millis / 60);
  13. int minutes = seconds / 60;
  14. seconds = seconds % 60;
  15.  
  16. txtcount.setText(String.format("%d:%02d:%02d", minutes, seconds,millis));
  17.  
  18. }
  19.  
  20. @Override
  21. public void onFinish() { }
  22. };
  23.  
  24. textView = (TextView) view.findViewById(R.id.textView1);
  25. final Timer t = new Timer("hello", true);
  26. t.schedule(new TimerTask() {
  27.  
  28. @Override
  29. public void run() {
  30. textView.post(new Runnable() {
  31.  
  32. public void run() {
  33. seconds++;
  34. if (seconds == 60) {
  35. seconds = 0;
  36. minute++;
  37. }
  38. if (minute == 60) {
  39. minute = 0;
  40. hour++;
  41. }
  42. textView.setText(""
  43. + (hour > 9 ? hour : ("0" + hour)) + " : "
  44. + (minute > 9 ? minute : ("0" + minute))
  45. + " : "
  46. + (seconds > 9 ? seconds : "0" + seconds));
  47.  
  48. }
  49. });
  50.  
  51. }
  52. }, 1000, 1000);
  53.  
  54. view.findViewById(R.id.stop).setOnClickListener(
  55. new OnClickListener() {
  56.  
  57. public void onClick(View v) {
  58. t.cancel();
  59. }
  60. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement