赞
踩
心想着也就是更新精确到分钟,不用精确到秒,定时器就没有必要,系统是有广播Intent.ACTION_TIME_TICK可以直接用
主方法里面调用一下
- //要先设置一下当前时间,不然刷新时间会等到1分钟后再刷新
- tv_HM.setText(getHM());
-
- IntentFilter filter=new IntentFilter();
- filter.addAction(Intent.ACTION_TIME_TICK);
- registerReceiver(receiver,filter);
- private final BroadcastReceiver receiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (action.equals(Intent.ACTION_TIME_TICK)) {
- tv_HM.setText(getHM());
- }
- }
- };
- public String getHM(){
- Calendar c = Calendar.getInstance();
- int hour = c.get(Calendar.HOUR_OF_DAY);
- int minute = c.get(Calendar.MINUTE);
- return hour + ":" +minute;
- }
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。