我正在我的应用中创建一个“进度”对话框。以下是我的代码......
ProgressDialog dialog = ProgressDialog.show(TabViewLayout.this, "", "Logout...");
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.isIndeterminate();
new Thread() {
public void run() {
try {
sleep(5000);
}
catch (Exception e) { }
}
}.start();
Handler handler = new Handler();
handler.post(new Runnable(){
public void run(){
dialog.dismiss();
}
});
我要做的是,我必须在我的应用程序中延迟5秒才能完成某个过程。使用上面的代码,进度对话框出现在屏幕上但旋转器没有旋转。我希望它在旋转模式下持续5秒钟。需要做什么?
答案 0 :(得分:4)
使用此代码可以帮助您
ProgressDialog progressDialog;
Context mContext;
private Thread mThread;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = this;
progressDialog = new ProgressDialog(mContext);
progressDialog.setCancelable(false);
progressDialog.setMessage("Loading....");
progressDialog.show();
mThread = new Thread() {
@Override
public void run() {
try {
synchronized (this) {
// Wait given period of time or exit on touch
wait(5000);
}
} catch (InterruptedException ex) {
}
// finish();
progressDialog.dismiss();
}
};
mThread.start();
}
答案 1 :(得分:0)
试试这段代码
ProgressDialog dialog = ProgressDialog.show(this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setMessage("Please wait...");
dialog.setCancelable(false);
dialog.show();
new Thread() {
public void run() {
try {
sleep(5000);
}
catch (Exception e) { }
}
}.start();
Handler handler = new Handler();
handler.post(new Runnable() {
public void run() {
dialog.dismiss();
}
});