I'm using the following code
new Thread(new Runnable() {
public void run() {
while (cont < 100) {
cont += 1;
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
progressBar.setVisibility(View.GONE);
}
}).start();
The problem is that at the time of setting Visibility the following error appears
FATAL EXCEPTION: Thread-1087 Process: br.alphatec.ms_caliente_alpha1, PID: 23000 android.view.ViewRootImpl $ CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
And when the code was running, it was very fast, and if I increase the value (100) that is in the while it stops working
new Thread(new Runnable() {
public void run() {
while (cont < 100) {
cont += 1;
}
progressBar.setVisibility(View.GONE);
}
}).start();