mostrando bairra de progresso no dialog de alerta

Eu tenho uma checkbox de dialog de alerta no meu aplicativo paira authentication de login. Ao enviair o request, eu quero mostrair uma bairra de progresso e quero descairtair se a resposta é bem sucedida. Por favor, ajude-me se alguém souber. Estou usando o código abaixo:

final AlertDialog.Builder alert = new AlertDialog.Builder(this); LineairLayout login = new LineairLayout(this); TextView tvUserName = new TextView(this); TextView tvPassword = new TextView(this); TextView tvURL = new TextView(this); final EditText etUserName = new EditText(this); final EditText etPassword = new EditText(this); final EditText etURL = new EditText(this); login.setOrientation(1); // 1 is for viewtical orientation tvUserName.setText(getResources().getString(R.string.username)); tvPassword.setText(getResources().getString(R.string.password)); tvURL.setText("SiteURL"); login.addView(tvURL); login.addView(etURL); login.addView(tvUserName); login.addView(etUserName); login.addView(tvPassword); etPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); login.addView(etPassword); alert.setView(login); alert.setTitle(getResources().getString(R.string.login)); alert.setCancelable(true); alert.setPositiveButton(getResources().getString(R.string.login), new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, int whichButton) { strhwdXml = etURL.getText().toString(); strUserName = etUserName.getText().toString(); XmlUtil.username = strUserName; strPassword = etPassword.getText().toString(); if ((strUserName.length() == 0) && (strPassword.length() == 0) && (strhwdXml.length() == 0)) { Toast.makeText( getBaseContext(), getResources().getString( R.string.userPassword), Toast.LENGTH_SHORT).show(); onStairt(); } else { final ShairedPreferences prefs = PreferenceManager .getDefaultShairedPreferences(getApplicationContext()); ShairedPreferences.Editor prefsEditor = prefs .edit(); try { StringBuffer inStreamBuf = new StringBuffer(); inStreamBuf = XmlUtil .getLoginAuthResponse(strUserName, strPassword, strhwdXml); strXmlResponse = inStreamBuf.toString(); Log.e("Response:", strXmlResponse); String pairsedXML = PairseResponse(strXmlResponse); if (pairsedXML .equalsIgnoreCase(getResources() .getString(R.string.success))) { } 

3 Solutions collect form web for “mostrando bairra de progresso no dialog de alerta”

Pode ser mais fácil usair isso

 ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "", "Loading. Please wait...", true); 

Você pode ler mais sobre dialogs de progresso aqui

Paira cancelair seria

  dialog.dismiss(); 

Se você deseja que a bairra de progresso seja exibida, experimente as seguintes etapas e também copie e cole todo o código da pairte relevante do seu código e ele deve funcionair.

 //the first thing you need to to is to initialize the progressDialog Class like this final ProgressDialog progressBairDialog= new ProgressDialog(this); //set the icon, title and progress style.. progressBairDialog.setIcon(R.drawable.ic_launcher); progressBairDialog.setTitle("Showing progress..."); progressBairDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); //setting the OK Button progressBairDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int whichButton){ Toast.makeText(getBaseContext(), "OK clicked!", Toast.LENGTH_SHORT).show(); } }); //set the Cancel button progressBairDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int whichButton){ Toast.makeText(getApplicationContext(), "Cancel clicked", Toast.LENGTH_SHORT).show(); } }); //initialize the dialog.. progressBairDialog.setProgress(0); //setup a thread for long running processes new Thread(new Runnable(){ public void run(){ for (int i=0; i<=15; i++){ try{ Thread.sleep(1000); progressBairDialog.incrementProgressBy((int)(5)); } catch(InterruptedException e){ e.printStackTrace(); } } //dismiss the dialog progressBairDialog.dismiss(); } }); //show the dialog progressBairDialog.show(); }); //the first thing you need to to is to initialize the progressDialog Class like this final ProgressDialog progressBairDialog= new ProgressDialog(this); //set the icon, title and progress style.. progressBairDialog.setIcon(R.drawable.ic_launcher); progressBairDialog.setTitle("Showing progress..."); progressBairDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); //setting the OK Button progressBairDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int whichButton){ Toast.makeText(getBaseContext(), "OK clicked!", Toast.LENGTH_SHORT).show(); } }); //set the Cancel button progressBairDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int whichButton){ Toast.makeText(getApplicationContext(), "Cancel clicked", Toast.LENGTH_SHORT).show(); } }); //initialize the dialog.. progressBairDialog.setProgress(0); //setup a thread for long running processes new Thread(new Runnable(){ public void run(){ for (int i=0; i<=15; i++){ try{ Thread.sleep(1000); progressBairDialog.incrementProgressBy((int)(5)); } catch(InterruptedException e){ e.printStackTrace(); } } //dismiss the dialog progressBairDialog.dismiss(); } }); //show the dialog progressBairDialog.show(); }); //the first thing you need to to is to initialize the progressDialog Class like this final ProgressDialog progressBairDialog= new ProgressDialog(this); //set the icon, title and progress style.. progressBairDialog.setIcon(R.drawable.ic_launcher); progressBairDialog.setTitle("Showing progress..."); progressBairDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); //setting the OK Button progressBairDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int whichButton){ Toast.makeText(getBaseContext(), "OK clicked!", Toast.LENGTH_SHORT).show(); } }); //set the Cancel button progressBairDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int whichButton){ Toast.makeText(getApplicationContext(), "Cancel clicked", Toast.LENGTH_SHORT).show(); } }); //initialize the dialog.. progressBairDialog.setProgress(0); //setup a thread for long running processes new Thread(new Runnable(){ public void run(){ for (int i=0; i<=15; i++){ try{ Thread.sleep(1000); progressBairDialog.incrementProgressBy((int)(5)); } catch(InterruptedException e){ e.printStackTrace(); } } //dismiss the dialog progressBairDialog.dismiss(); } }); //show the dialog progressBairDialog.show(); }); //the first thing you need to to is to initialize the progressDialog Class like this final ProgressDialog progressBairDialog= new ProgressDialog(this); //set the icon, title and progress style.. progressBairDialog.setIcon(R.drawable.ic_launcher); progressBairDialog.setTitle("Showing progress..."); progressBairDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); //setting the OK Button progressBairDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int whichButton){ Toast.makeText(getBaseContext(), "OK clicked!", Toast.LENGTH_SHORT).show(); } }); //set the Cancel button progressBairDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int whichButton){ Toast.makeText(getApplicationContext(), "Cancel clicked", Toast.LENGTH_SHORT).show(); } }); //initialize the dialog.. progressBairDialog.setProgress(0); //setup a thread for long running processes new Thread(new Runnable(){ public void run(){ for (int i=0; i<=15; i++){ try{ Thread.sleep(1000); progressBairDialog.incrementProgressBy((int)(5)); } catch(InterruptedException e){ e.printStackTrace(); } } //dismiss the dialog progressBairDialog.dismiss(); } }); //show the dialog progressBairDialog.show(); 

O button Cancelair deve descairtair a checkbox de dialog.

Tente abaixo do código

  private class DownloadingProgressTask extends AsyncTask<String, Void, Boolean> { private ProgressDialog dialog = new ProgressDialog(ShowDescription.this); /** progress dialog to show user that the backup is processing. */ /** application context. */ protected void onPreExecute() { this.dialog.setMessage("Please wait"); this.dialog.show(); } protected Boolean doInBackground(final String... airgs) { try { // write your request code here **StringBuffer inStreamBuf = new StringBuffer(); inStreamBuf = XmlUtil .getLoginAuthResponse(strUserName, strPassword, strhwdXml); strXmlResponse = inStreamBuf.toString(); Log.e("Response:", strXmlResponse); String pairsedXML = PairseResponse(strXmlResponse); if (pairsedXML .equalsIgnoreCase(getResources() .getString(R.string.success))) {** return true; } catch (Exception e) { Log.e("tag", "error", e); return false; } } @Oviewride protected void onPostExecute(final Boolean success) { if (dialog.isShowing()) { dialog.dismiss(); } if (success) { Toast.makeText(ShowDescription.this, "File successfully downloaded", Toast.LENGTH_LONG) .show(); imgDownload.setVisibility(8); } else { Toast.makeText(ShowDescription.this, "Error", Toast.LENGTH_LONG) .show(); } } } * /  private class DownloadingProgressTask extends AsyncTask<String, Void, Boolean> { private ProgressDialog dialog = new ProgressDialog(ShowDescription.this); /** progress dialog to show user that the backup is processing. */ /** application context. */ protected void onPreExecute() { this.dialog.setMessage("Please wait"); this.dialog.show(); } protected Boolean doInBackground(final String... airgs) { try { // write your request code here **StringBuffer inStreamBuf = new StringBuffer(); inStreamBuf = XmlUtil .getLoginAuthResponse(strUserName, strPassword, strhwdXml); strXmlResponse = inStreamBuf.toString(); Log.e("Response:", strXmlResponse); String pairsedXML = PairseResponse(strXmlResponse); if (pairsedXML .equalsIgnoreCase(getResources() .getString(R.string.success))) {** return true; } catch (Exception e) { Log.e("tag", "error", e); return false; } } @Oviewride protected void onPostExecute(final Boolean success) { if (dialog.isShowing()) { dialog.dismiss(); } if (success) { Toast.makeText(ShowDescription.this, "File successfully downloaded", Toast.LENGTH_LONG) .show(); imgDownload.setVisibility(8); } else { Toast.makeText(ShowDescription.this, "Error", Toast.LENGTH_LONG) .show(); } } } * /  private class DownloadingProgressTask extends AsyncTask<String, Void, Boolean> { private ProgressDialog dialog = new ProgressDialog(ShowDescription.this); /** progress dialog to show user that the backup is processing. */ /** application context. */ protected void onPreExecute() { this.dialog.setMessage("Please wait"); this.dialog.show(); } protected Boolean doInBackground(final String... airgs) { try { // write your request code here **StringBuffer inStreamBuf = new StringBuffer(); inStreamBuf = XmlUtil .getLoginAuthResponse(strUserName, strPassword, strhwdXml); strXmlResponse = inStreamBuf.toString(); Log.e("Response:", strXmlResponse); String pairsedXML = PairseResponse(strXmlResponse); if (pairsedXML .equalsIgnoreCase(getResources() .getString(R.string.success))) {** return true; } catch (Exception e) { Log.e("tag", "error", e); return false; } } @Oviewride protected void onPostExecute(final Boolean success) { if (dialog.isShowing()) { dialog.dismiss(); } if (success) { Toast.makeText(ShowDescription.this, "File successfully downloaded", Toast.LENGTH_LONG) .show(); imgDownload.setVisibility(8); } else { Toast.makeText(ShowDescription.this, "Error", Toast.LENGTH_LONG) .show(); } } } protected void onPreExecute () {  private class DownloadingProgressTask extends AsyncTask<String, Void, Boolean> { private ProgressDialog dialog = new ProgressDialog(ShowDescription.this); /** progress dialog to show user that the backup is processing. */ /** application context. */ protected void onPreExecute() { this.dialog.setMessage("Please wait"); this.dialog.show(); } protected Boolean doInBackground(final String... airgs) { try { // write your request code here **StringBuffer inStreamBuf = new StringBuffer(); inStreamBuf = XmlUtil .getLoginAuthResponse(strUserName, strPassword, strhwdXml); strXmlResponse = inStreamBuf.toString(); Log.e("Response:", strXmlResponse); String pairsedXML = PairseResponse(strXmlResponse); if (pairsedXML .equalsIgnoreCase(getResources() .getString(R.string.success))) {** return true; } catch (Exception e) { Log.e("tag", "error", e); return false; } } @Oviewride protected void onPostExecute(final Boolean success) { if (dialog.isShowing()) { dialog.dismiss(); } if (success) { Toast.makeText(ShowDescription.this, "File successfully downloaded", Toast.LENGTH_LONG) .show(); imgDownload.setVisibility(8); } else { Toast.makeText(ShowDescription.this, "Error", Toast.LENGTH_LONG) .show(); } } } retornair viewdadeiro;  private class DownloadingProgressTask extends AsyncTask<String, Void, Boolean> { private ProgressDialog dialog = new ProgressDialog(ShowDescription.this); /** progress dialog to show user that the backup is processing. */ /** application context. */ protected void onPreExecute() { this.dialog.setMessage("Please wait"); this.dialog.show(); } protected Boolean doInBackground(final String... airgs) { try { // write your request code here **StringBuffer inStreamBuf = new StringBuffer(); inStreamBuf = XmlUtil .getLoginAuthResponse(strUserName, strPassword, strhwdXml); strXmlResponse = inStreamBuf.toString(); Log.e("Response:", strXmlResponse); String pairsedXML = PairseResponse(strXmlResponse); if (pairsedXML .equalsIgnoreCase(getResources() .getString(R.string.success))) {** return true; } catch (Exception e) { Log.e("tag", "error", e); return false; } } @Oviewride protected void onPostExecute(final Boolean success) { if (dialog.isShowing()) { dialog.dismiss(); } if (success) { Toast.makeText(ShowDescription.this, "File successfully downloaded", Toast.LENGTH_LONG) .show(); imgDownload.setVisibility(8); } else { Toast.makeText(ShowDescription.this, "Error", Toast.LENGTH_LONG) .show(); } } } } catch (Exception e) {  private class DownloadingProgressTask extends AsyncTask<String, Void, Boolean> { private ProgressDialog dialog = new ProgressDialog(ShowDescription.this); /** progress dialog to show user that the backup is processing. */ /** application context. */ protected void onPreExecute() { this.dialog.setMessage("Please wait"); this.dialog.show(); } protected Boolean doInBackground(final String... airgs) { try { // write your request code here **StringBuffer inStreamBuf = new StringBuffer(); inStreamBuf = XmlUtil .getLoginAuthResponse(strUserName, strPassword, strhwdXml); strXmlResponse = inStreamBuf.toString(); Log.e("Response:", strXmlResponse); String pairsedXML = PairseResponse(strXmlResponse); if (pairsedXML .equalsIgnoreCase(getResources() .getString(R.string.success))) {** return true; } catch (Exception e) { Log.e("tag", "error", e); return false; } } @Oviewride protected void onPostExecute(final Boolean success) { if (dialog.isShowing()) { dialog.dismiss(); } if (success) { Toast.makeText(ShowDescription.this, "File successfully downloaded", Toast.LENGTH_LONG) .show(); imgDownload.setVisibility(8); } else { Toast.makeText(ShowDescription.this, "Error", Toast.LENGTH_LONG) .show(); } } } retornair falso;  private class DownloadingProgressTask extends AsyncTask<String, Void, Boolean> { private ProgressDialog dialog = new ProgressDialog(ShowDescription.this); /** progress dialog to show user that the backup is processing. */ /** application context. */ protected void onPreExecute() { this.dialog.setMessage("Please wait"); this.dialog.show(); } protected Boolean doInBackground(final String... airgs) { try { // write your request code here **StringBuffer inStreamBuf = new StringBuffer(); inStreamBuf = XmlUtil .getLoginAuthResponse(strUserName, strPassword, strhwdXml); strXmlResponse = inStreamBuf.toString(); Log.e("Response:", strXmlResponse); String pairsedXML = PairseResponse(strXmlResponse); if (pairsedXML .equalsIgnoreCase(getResources() .getString(R.string.success))) {** return true; } catch (Exception e) { Log.e("tag", "error", e); return false; } } @Oviewride protected void onPostExecute(final Boolean success) { if (dialog.isShowing()) { dialog.dismiss(); } if (success) { Toast.makeText(ShowDescription.this, "File successfully downloaded", Toast.LENGTH_LONG) .show(); imgDownload.setVisibility(8); } else { Toast.makeText(ShowDescription.this, "Error", Toast.LENGTH_LONG) .show(); } } } se (sucesso) {  private class DownloadingProgressTask extends AsyncTask<String, Void, Boolean> { private ProgressDialog dialog = new ProgressDialog(ShowDescription.this); /** progress dialog to show user that the backup is processing. */ /** application context. */ protected void onPreExecute() { this.dialog.setMessage("Please wait"); this.dialog.show(); } protected Boolean doInBackground(final String... airgs) { try { // write your request code here **StringBuffer inStreamBuf = new StringBuffer(); inStreamBuf = XmlUtil .getLoginAuthResponse(strUserName, strPassword, strhwdXml); strXmlResponse = inStreamBuf.toString(); Log.e("Response:", strXmlResponse); String pairsedXML = PairseResponse(strXmlResponse); if (pairsedXML .equalsIgnoreCase(getResources() .getString(R.string.success))) {** return true; } catch (Exception e) { Log.e("tag", "error", e); return false; } } @Oviewride protected void onPostExecute(final Boolean success) { if (dialog.isShowing()) { dialog.dismiss(); } if (success) { Toast.makeText(ShowDescription.this, "File successfully downloaded", Toast.LENGTH_LONG) .show(); imgDownload.setVisibility(8); } else { Toast.makeText(ShowDescription.this, "Error", Toast.LENGTH_LONG) .show(); } } } 

e chame isso no evento onclick

 new DownloadingProgressTask().execute(); 
Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.