android 计数器
来源:互联网 发布:cnpm 安装node sass 编辑:程序博客网 时间:2024/06/01 03:57
//时间计数器,最多只能到99小时,如需要更大小时数需要改改方法
public String showTimeCount(long time) {
if(time >= 360000000){
return "00:00:00";
}
String timeCount = "";
long hourc = time/3600000;
String hour = "0" + hourc;
hour = hour.substring(hour.length()-2, hour.length());
long minuec = (time-hourc*3600000)/(60000);
String minue = "0" + minuec;
minue = minue.substring(minue.length()-2, minue.length());
long secc = (time-hourc*3600000-minuec*60000)/1000;
String sec = "0" + secc;
sec = sec.substring(sec.length()-2, sec.length());
timeCount = hour + ":" + minue + ":" + sec;
return timeCount;
}
private Handler stepTimeHandler;
private Runnable mTicker;
long startTime = 0;
//开始按钮
class startBtnListener implements OnClickListener {
@Override
public void onClick(View v) {
Button b = (Button)v;
String buttonText = b.getText().toString();
if("Start".equalsIgnoreCase(buttonText)){
b.setText("Stop");
// 清零 开始计时
stepTimeTV.setText("00:00:00");
stepTimeHandler = new Handler();
startTime = System.currentTimeMillis();
mTicker = new Runnable() {
public void run() {
String content = showTimeCount(System.currentTimeMillis() - startTime);
stepTimeTV.setText(content);
long now = SystemClock.uptimeMillis();
long next = now + (1000 - now % 1000);
stepTimeHandler.postAtTime(mTicker, next);
}
};
//启动计时线程,定时更新
mTicker.run();
}else{
b.setText("Start");
//停止计时 Remove any pending posts of Runnable r that are in the message queue.
stepTimeHandler.removeCallbacks(mTicker);
}
}
}
public String showTimeCount(long time) {
if(time >= 360000000){
return "00:00:00";
}
String timeCount = "";
long hourc = time/3600000;
String hour = "0" + hourc;
hour = hour.substring(hour.length()-2, hour.length());
long minuec = (time-hourc*3600000)/(60000);
String minue = "0" + minuec;
minue = minue.substring(minue.length()-2, minue.length());
long secc = (time-hourc*3600000-minuec*60000)/1000;
String sec = "0" + secc;
sec = sec.substring(sec.length()-2, sec.length());
timeCount = hour + ":" + minue + ":" + sec;
return timeCount;
}
private Handler stepTimeHandler;
private Runnable mTicker;
long startTime = 0;
//开始按钮
class startBtnListener implements OnClickListener {
@Override
public void onClick(View v) {
Button b = (Button)v;
String buttonText = b.getText().toString();
if("Start".equalsIgnoreCase(buttonText)){
b.setText("Stop");
// 清零 开始计时
stepTimeTV.setText("00:00:00");
stepTimeHandler = new Handler();
startTime = System.currentTimeMillis();
mTicker = new Runnable() {
public void run() {
String content = showTimeCount(System.currentTimeMillis() - startTime);
stepTimeTV.setText(content);
long now = SystemClock.uptimeMillis();
long next = now + (1000 - now % 1000);
stepTimeHandler.postAtTime(mTicker, next);
}
};
//启动计时线程,定时更新
mTicker.run();
}else{
b.setText("Start");
//停止计时 Remove any pending posts of Runnable r that are in the message queue.
stepTimeHandler.removeCallbacks(mTicker);
}
}
}
0 0
- android 计数器
- Android实现计数器功能
- android 计数器---定时执行任务
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- NSUserDefault的plist文件的位置
- 推送通知
- 零基础入门jQuery视频教程
- CentOS6 离线bash漏洞修复方法
- Note7:String regionMatches查询一段话里有没有关键字 indexOf值得注意的地方
- android 计数器
- 输出一个数的全排列
- Windows7:Visual Studio 2008试用版的评估期已经结束解决方法
- 【HDU】5016 Mart Master II 点分治
- 可扩展类库强制取消异步调用
- 嵌入式 probe()函数是什么时候被调用,设备和驱动是怎么联系起来的
- android开发:SD卡,Assets目录,data/data目录下,数据库的复制操作
- 【转】一个华为人辞职创业后的几个反思
- 根据模板生成Excel