Can I wait until the end of the toast to resume this method?

In one of my methods, I have toastone that appears if the user enters the correct input. However, I do not want the next image to be displayed until the toast ends.

If I use Thread.sleep(3000), if it doesn’t allow me to toastshow when the user interface activity is sleeping.

An example of what I'm trying to do:

public void correction(){
        if(correctionBoolean == true){  
            Toast.makeText(this, "Correct!", Toast.LENGTH_SHORT).show();    
            if(Toast.time == finished){
            NextImage();}
            }
+3
source share
3 answers

I do not believe that with a toast one could do this. If you are just trying to show someone the "You are correct" window, I would just try using AlertDialog with one positive Okay button.

, , .

+5

, , .

+4

Use CountDownTimerwith Toast.LENGTH_SHORTwhat time?

public void correction(){
    if(correctionBoolean == true){  
        Toast.makeText(this, "Correct!", Toast.LENGTH_SHORT).show();    
        new CountdownTimer(Toast.LENGTH_SHORT, 1000) {

            public void onTick(long millisUntilFinished) {

        }

        public void onFinish() {
            NextImage();
        }
        }.start();

}
+1
source

All Articles