简体   繁体   中英

how to add button dynamically to progress dialog android?

I added dynamic message successfully to my progressdialog.But when adding the button it doesn't take the button Please help me out.

private Handler progressHandler = new Handler() {

            @Override
            public void handleMessage(Message msg) {

                // process incoming messages here
                switch (msg.what) {

                case 0:
                    // update progress bar
                    progressDialog.setMessage("" + (String) msg.obj);
                    break;
                case 1:
                    progressDialog.setMessage("" + (String) msg.obj);
                    finish();
                    break;
                case 2:
                    Log.d(TAG,"in case 2.........");
//                  progressDialog.cancel();
                    progressDialog.setMessage("" + (String) msg.obj);
                    progressDialog.setButton("HOME", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
//                          progressDialog.cancel();
                            finish();

                        }
                    });
                    break;

                }
                super.handleMessage(msg);
            }

        };

Regards, Rajendar Are

I simply changed the code to this way for my convience.

private Handler progressHandler = new Handler() {

            @Override
            public void handleMessage(Message msg) {

                // process incoming messages here
                switch (msg.what) {

                case 0:
                    // update progress bar
                    progressDialog = new ProgressDialog(context);

                    progressDialog.setMessage("" + (String) msg.obj);
                    progressDialog.show();
                    break;

                case 1:
                    Log.d(TAG,"in case 1.........");
                    progressDialog.dismiss();


                     AlertDialog.Builder builder = new AlertDialog.Builder(context);
                       AlertDialog alertDialog = builder.create();
                       alertDialog.setTitle("Dialog");
                       alertDialog.setMessage("" + (String) msg.obj);
                       alertDialog.setButton("HOME", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            finish();

                        }
                    });
                    alertDialog.show();


                    break;

                }
                super.handleMessage(msg);
            }

        };

If any one know how to add dynamic button to progress dialog please reply.

Regards, Rajendar Are.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM