如何在线程等待时显示进度条

时间:2016-01-22 10:01:29

标签: android progressdialog

dialog = new ProgressDialog(activity);
dialog.show();
    synchronized (this) {
            Log.d(LOG_TAG, "Waiting for closed rides to be loaded");
            try {
                wait();

            } catch (InterruptedException e) {

            }
        }
    }
    dialog.dismiss();

我已经尝试将上面的代码用于进度条,但是如何不显示进度条

2 个答案:

答案 0 :(得分:1)

您正在创建ProgressDialog并立即解除它,因为您的不同线程正在等待而不是创建ProgressDialog的线程。这意味着dialog.show()dialog.dismiss()一个接一个地执行,这就是你无法看到对话框的原因。

 dialog.dismiss();

之后

wait();

答案 1 :(得分:-1)

我觉得这个适合你

     final Dialog login = new Dialog(this);
            // Set GUI of login screen
            login.setContentView(R.layout.forgot_password);
            login.setTitle(R.string.Forgot_Password );
            login.setCancelable(true);

            // Init button of login GUI
            Button btnLogin = (Button) login.findViewById(R.id.btnSend);
            Button btnCancel = (Button) login.findViewById(R.id.btnCancel);

   TextView tvForgotUsername =  (TextView)login.findViewById(R.id.tvForgotUsername);
            tvForgotUsername.setText(R.string.Forgot_Username);
            etForgot = (EditText) login.findViewById(R.id.txtUsername);
            etForgot.setVisibility(View.VISIBLE);


            // Attached listener for login GUI button
            btnLogin.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (etForgot.getText().toString().trim().length() > 0) {
   Toast.makeText(LoginScreenActivity.this,"Email will be send to your email address", Toast.LENGTH_LONG).show();
                            login.dismiss();

                }
            });
            btnCancel.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    login.dismiss();
                }
            });
            // Make dialog box visible.
            login.show();