我需要一个函数,在我的新Android应用中将应用程序超时3秒。我尝试了这样的函数“sleep()”:
seekBar1.setProgress(50); // Set something for my SeekBar
try{
Thread.sleep(3000); // Wait for 3 Seconds
} catch (Exception e){
System.out.println("Error: "+e); // Catch the exception
}
button.setEnabled(true); // Enable my button
看起来它可以工作,但如果我正在运行应用程序,它会这样做:等待3秒钟,设置进度并启用按钮。 我想先设置进度,然后等待3秒钟,然后才启用按钮。
"sleep()"对于我的用途是否正确,还是我还能做些什么以使我的应用程序按正确顺序执行?
new Handler().postDelayed(new Runnable() { @Override public void run() { button.setEnable(true); } },3000);
。 - Konrad Krakowiak