I have a method in which I want a delay of a second, and while the delay is running there should be a loading animation (ProgressBar
).
Right now, when the method is now running the loading animation is not appearing. If I do not call the Timeout
it does appear, and when I do not make it invisible after, it shows up after the timeout.
How do I show the loading animation while the timeout is running? I have a similar problem trying to do with with Thread.sleep(1000)
.
public void firstMethod(){
ProgressBar pgLoading = (ProgressBar) findViewById(R.id.pgLoading);
pgLoading.setVisibility(VISIBLE);
try {
TimeUnit.SECONDS.sleep(1);
}catch(InterruptionException ex){
ex.printStackTrace();
}
pgLoading.setVisibility(INVISIBLE);
}