Skip to content Skip to sidebar Skip to footer

How To Open ProgressBar Inside The AlertDailog?

i m newcomer in android. i am faceing some trouble my Scenarios is -when i click button so open alertDailog and alertdailog have two button like send and cancel,when i click send b

Solution 1:

I have also used Progressdialog in click event of Alertdialog.The code is below:

AlertDialog.Builder submitalert = new AlertDialog.Builder(Summary.this);
 submitalert.setTitle(getResources().getString(R.string.app_name))
.setMessage("Submit the data to database?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener(){

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    update.setTitle(getResources().getString(R.string.app_name));
                    update.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                    update.setCancelable(true);
                    update.setMax(100);
                    update.show();


                    Thread background = new Thread (new Runnable() {
                           public void run() {
                               try {
                                   // enter the code to be run while displaying the progressbar.
                                   //
                                   // This example is just going to increment the progress bar:
                                   // So keep running until the progress value reaches maximum value
                                   while (update.getProgress()<= update.getMax()) {
                                       // wait 500ms between each update
                                       Thread.sleep(500);

                                       // active the update handler
                                       progressHandler.sendMessage(progressHandler.obtainMessage());
                                   }

                               } catch (java.lang.InterruptedException e) {
                                   // if something fails do something smart
                               }
                           }
                        });

                        // start the background thread
                        background.start();
                        if(update.getProgress()== 100)
                           {
                               update.dismiss();
                           }
                    }




            })
            .setNegativeButton("No", new DialogInterface.OnClickListener(){
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub

                }
            })
            .show();

Post a Comment for "How To Open ProgressBar Inside The AlertDailog?"