Skip to content Skip to sidebar Skip to footer

Is There An Approach Which Can Delay Certain Seconds Between Every Function Call Which Need To Update Ui Components?

I am writing a maze game, and one of its features is 'Show solution'. The solution may contain many steps, I am using a for loop to iterate every step, in order to show it clear to

Solution 1:

You can use a countdown timer.

 new CountDownTimer(30000, 1000){
                    public void onTick(long millisUntilFinished){
                        doUpdateOnEveryTick()
                    }
                    public  void onFinish(){
                       doActionOnFinish()
                    }
                }.start();

Solution 2:

Try something like this,

publicvoidshowSolution(View view) {
// Do something longRunnablerunnable=newRunnable() {
    @Overridepublicvoidrun() {
intstage= currentGame.currentStage;
    int[][] solution = GameMap.solutionList[stage];
    drawStage(stage);
    for(int[] step: solution) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            handler.post(newRunnable() {
                @Overridepublicvoidrun() {
                       ImageViewv= (ImageView)findViewById(viewIdList[step[0]][step[1]]);
        setTimeout(() -> {v.callOnClick();}, 1);
                }
            });
        }
    }
};
newThread(runnable).start();
}

Post a Comment for "Is There An Approach Which Can Delay Certain Seconds Between Every Function Call Which Need To Update Ui Components?"