繁体   English   中英

如何动态添加按钮以进度对话框android?

[英]how to add button dynamically to progress dialog android?

我已将动态消息成功添加到进度对话框中。但是添加按钮时,按钮并没有显示按钮,请帮帮我。

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

        };

问候,拉杰达尔

为方便起见,我只是将代码更改为这种方式。

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

        };

如果有人知道如何在进度对话框中添加动态按钮,请回复。

问候,拉杰达尔。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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