1

I am creating one Progress dialog in my app. Below is my code...

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();
                     }
             });

What I have to do is, I have to put delay for 5 seconds in my app for some process. With above code, progress dialog is appearing on screen but spinner is not spinning. I want it in spinning mode for 5 seconds. What needs to be done?

4

2 回答 2

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();
}
于 2013-09-13T12:55:01.567 回答
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();
                 }
             });
于 2013-09-13T12:30:49.143 回答