public class ForRun{
private Handler hand=new Handler();
private int time=60;
private boolean isruning=false;
private OnRunListener orl;
private int count=0;
public ForRun(OnRunListener orl){this.orl=orl;}
public ForRun(int time,OnRunListener orl){
this.orl=orl;this.time=time;
}
public void setTime(int time){this.time=time;}
public void start(){isruning=true;update();}
public void stop(){isruning=false;}
private void update(){hand.postDelayed(new tick(),time);}
private class tick implements Runnable{
@Override public void run(){
if(orl!=null)isruning=orl.run(count++);
if(isruning)update();}
}
public static interface OnRunListener{
public boolean run(int count);
}
}