2016-01-22 40 views
0
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(); 

我一直在使用上面的進度條,進度條是怎麼過不顯示如何顯示進度條,當線程等待

+0

您立即調用解僱進度條,所以從活動其解聘。評論該行並檢查。 –

+1

爲什麼這樣做?你的要求是什麼?有最好的方法來使用Asynctask或處理器 –

回答

1

您所創建的ProgressDialog並立即解僱,是因爲你的不同代碼試圖線程正在等待而不是創建了ProgressDialog的線程。這意味着dialog.show()dialog.dismiss()一個接一個地執行,這就是爲什麼你不能看到對話框。

dialog.dismiss(); 

wait(); 
+0

我已經嘗試過,但它不工作 –

+0

@LakshmiKanth:嘗試給予'wait()'一個持續時間,如'wait(5000)'。 – Rohit5k2

+0

從另一種方法,我們正在通知某些條件同步(this){0}。 } –

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