/** * 阻止在极短的时间重复执行某个函数中的代码 * @author wanlh * */ public class ReEventsController { private boolean isRepeatFlag = false; private MyRunnable mMyRunnable; private class MyRunnable implements Runnable{ @Override public void run() { // TODO Auto-generated method stub isRepeatFlag = false; } } /** * 在time时间之内是否重复,阻止代码往下执行 * @param view * @param time * @return */ public boolean isRepeat(View view, int time){ if(mMyRunnable == null) mMyRunnable = new MyRunnable(); if(isRepeatFlag){ //view.removeCallbacks(mMyRunnable); //view.postDelayed(mMyRunnable, time);//2500毫秒恢复,300毫秒之内不允许重复请求数据 return true; }else{ isRepeatFlag = true; view.removeCallbacks(mMyRunnable); view.postDelayed(mMyRunnable, time);//2500毫秒恢复,300毫秒之内不允许重复请求数据 } return false; } }
view是WebView.
本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/5563046.html,如需转载请自行联系原作者