偷懒代码块之数字时钟效果
2015-11-25 14:30
302 查看
贴代码备忘~
public class MainActivity extends Activity { private TextView tv; private static long start,now; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.tvTime); start = System.currentTimeMillis(); handle.post(runnable); } 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; } Handler handle = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { handle.postDelayed(this, 500); now = System.currentTimeMillis(); long time = now - start; tv.setText(showTimeCount(time)); Log.i("0630","handle -- running"); } }; }
相关文章推荐
- Python之打包一键自动化脚本(针对cmt设备)
- java.io.tmpdir 所指地址
- Java中需要注意的3个常见集合错误
- 【java基础】JPA详解(part2)
- java怎么把数据库的内容导出到excel表里面
- java匹配电话格式的正则表达式
- 【Java基础】JPA详解(part1)
- ngnix 集群和配置(mysql ,fast php 安装)
- c语言返回栈内存的问题
- 使用 ServKit(PHPnow) 搭建 PHP 环境
- 开源作品-ThinkPHP在线分析工具(单文件绿色版)-TPLogAnalysis_PHP_1_0
- c++ ftream
- Git配置及GitHub的基础使用(Win及Ubuntu)
- FileInputStream 读取txt文件内容
- [基础] - Python中 raw_input 和 input 的区别
- C# 之 Linq 学习笔记
- Java RTTI初探
- 在mac os安装CocoaPods(最详细教程)
- 关于Java中的paint,repaint,update三个方法的关系
- 编程学习游戏(2)CodinGame