在应用警告对话框中的所需功能后,如何关闭进度对话框?

时间:2016-03-04 14:33:00

标签: android android-view android-alertdialog android-progressbar android-runonuithread

我的片段中有一个链接,显示“点击打开对话框”,单击它后会弹出一个警告对话框,显示“是否要更改视图?”,带有是和否符号。如果我单击否,则没有任何反应,对话框会按预期消失。但是,如果我单击是,如何调用函数来刷新我的视图,直到我的视图刷新显示进度对话框?到目前为止,这是我的代码,我不知道在哪里解除进度对话框或确保视图刷新,任何线索? :

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("Are you sure you want to refresh your view?");
        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                //refreshview here ? 

                ProgressDialog progressDialog = ProgressDialog.show(getActivity(), "",
                        "Loading. Please wait...", true);
                progressDialog.show();

                progressDialog.setCancelable(false);
                progressDialog.setCanceledOnTouchOutside(false);
            }
        });
        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();

2 个答案:

答案 0 :(得分:2)

最好在AsyncTask点击您的onPostExecute(...)

看看演示

  1. Official Page
  2. Examples
  3. Progress Dialog

    中刷新View数据后

    编辑:

    onPostExecute(...)

    此代码在10秒后执行。

答案 1 :(得分:0)

如果你没有对新线程进行任何操作,则不需要处理程序。只需调用以下方法:

private void updateView(ProgressDialog dialog){
   //UPDATE
   if(dialog != null){
     dialog.dismiss();
   } 
}