zoukankan      html  css  js  c++  java
  • Chronometer 计时器使用

     1 public class TestProject extends Activity {
     2     TextView textGoesHere;
     3     long startTime;
     4     long countUp;
     5 
     6     @Override
     7     public void onCreate(Bundle savedInstanceState) {
     8         super.onCreate(savedInstanceState);
     9         setContentView(R.layout.main);
    10 
    11         Chronometer stopWatch = (Chronometer) findViewById(R.id.chrono);
    12         startTime = SystemClock.elapsedRealtime();
    13 
    14         textGoesHere = (TextView) findViewById(R.id.textGoesHere);
    15         stopWatch.setOnChronometerTickListener(new OnChronometerTickListener(){
    16             @Override
    17             public void onChronometerTick(Chronometer arg0) {
    18                 countUp = (SystemClock.elapsedRealtime() - arg0.getBase()) / 1000;
    19                 String asText = (countUp / 60) + ":" + (countUp % 60); 
    20                 textGoesHere.setText(asText);
    21             }
    22         });
    23         stopWatch.start();
    24     }
    25 }
    <Chronometer android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/chrono"
        android:visibility="gone"/>
  • 相关阅读:
    leetcode 对称二叉树
    leetcode 验证二叉搜索树
    蓝桥杯 完美的代价 贪心
    蓝桥杯 字符串对比 模拟
    蓝桥杯 芯片测试 极限找规律
    蓝桥杯 2n皇后问题 深搜
    74. 搜索二维矩阵
    二分 34
    二分 35
    二分 69
  • 原文地址:https://www.cnblogs.com/ikaka/p/3627830.html
Copyright © 2011-2022 走看看