So, I have a program which, when pressing a button, changes an image src programmatically (with a method I made) then calls another method I made, but I want for the second method to be called after a delay of a few seconds. I already tried Thread.sleep(5000)
, java.util.concurrent.TimeUnit.SECONDS.sleep(2)
, and wait()
but all of these pauses the whole program hindering the change of the image src.
Here is the code :
public void onButtonClickListenerGoHit(int buttonId) {
button_test = findViewById(buttonId);
button_test.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
changeImage(R.id.imageView2, R.drawable.lodef);
gameOver();
}
}
);
}
So what I want is for the gameOver()
to be called a few seconds after changeImage()
.