网上搜索有介绍使用Sleep
方法实现的,这里就不介绍了java
Handler handler=new Handler(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Runnable runnable=new Runnable() { @Override public void run() { Log.i(TAG,sdf.format(System.currentTimeMillis())); handler.postDelayed(this, 2000); } };
handler.postDelayed(runnable,1000);//每两秒执行一次runnable.
ide
handler.removeCallbacks(runnable);
post
启动定时器中的 1000
表示点击按钮1秒钟后启动定时器runnable
中的 2000
表示每2秒钟执行一次this