如何在alertdialog中添加循环进度条?

时间:2017-05-28 09:59:48

标签: android

我正在从服务中显示AlertDialog。问题是,我想在ProgressBar中添加AlertDialog(循环)。我该怎么做呢?我尝试用AlertDialog替换ProgressDialog,但它会强制关闭,我知道这不是正确的方法。

 AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("APP IS OBSOLETE")
                    .setMessage("To continue, please wait for the updates to download.")
                    .setCancelable(false)
                    .setPositiveButton("no, thanks", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            System.exit(0);
                        }
                    });
            AlertDialog alert = builder.create();
            alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            alert.show();

PS:我想在服务中执行此操作,而不使用任何其他布局。

2 个答案:

答案 0 :(得分:0)

您仍应使用AlertDialog,但要更改其显示的View

https://developer.android.com/reference/android/app/Dialog.html#setContentView(android.view.View)

        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setView(R.layout.my_progress_view)
        ...

在构建器上使用此方法:https://developer.android.com/reference/android/app/AlertDialog.Builder.html#setView(int)

R.layout.my_progress_view是一个包含ProgressBar的XML文件(您创建它的方式与创建活动布局的方式相同)

答案 1 :(得分:0)

您应该使用dialog.getContext()代替上下文

Matrix_B$Results <- ifelse((Matrix_A$R %in% Matrix_B$R) & 
                        (Matrix_A$NS %in% Matrix_B$NS),1,0))