I want to repeat execution of some codes after a delay. Following is the code.
public void hintrun(int i){
Handler handler = new Handler();
for(int j = 1; j< i+1;j++) {
handler.postDelayed(new Runna(j), 1000);
}
}
class Runna implements Runnable {
private int j;
public Runna(int j2) {
j=j2;
}
public void run() {
// some code
}
}
But it is not working. If say the for loop runs 3 times, then the code is run three times immediately after 1000 ms. I want a gap of 1000 ms between each execution.
You can simply change your code of loop this way,