在应用警报对话框中的所需功能后,如何关闭我的进度对话框?
how do I dismiss my progress dialog after the needed function in alert dialog is applied?
我的片段中有一个 link,它显示“单击以打开对话框”,单击它后会弹出一个警告对话框,显示“您要更改视图吗?”是和没有符号。如果我单击否,则不会发生任何事情,并且对话框会按预期关闭。但是,如果我单击“是”,如何调用一个函数来刷新我的视图,并在我的视图刷新之前显示一个进度对话框?到目前为止,这是我的代码,我不知道在哪里关闭进度对话框或确保刷新视图,有什么线索吗? :
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();
最好在此处和 onPostExecute(...)
中使用 AsyncTask
关闭您的 Progress Dialog
看看演示
- Official Page
- Examples
获得数据后,在 onPostExecute(...)
中刷新 View
编辑:
//Progress Dialog Show logic here
Runnable r=new Runnable() {
@Override
public void run() {
//Dismiss the Dialog and refresh your Views
}
};
new Handler().postDelayed(r,10*1000);
此代码在 10 秒后执行
如果您不在新线程上执行任何操作,则不需要处理程序。只需调用如下方法:
private void updateView(ProgressDialog dialog){
//UPDATE
if(dialog != null){
dialog.dismiss();
}
}
我的片段中有一个 link,它显示“单击以打开对话框”,单击它后会弹出一个警告对话框,显示“您要更改视图吗?”是和没有符号。如果我单击否,则不会发生任何事情,并且对话框会按预期关闭。但是,如果我单击“是”,如何调用一个函数来刷新我的视图,并在我的视图刷新之前显示一个进度对话框?到目前为止,这是我的代码,我不知道在哪里关闭进度对话框或确保刷新视图,有什么线索吗? :
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();
最好在此处和 onPostExecute(...)
中使用 AsyncTask
关闭您的 Progress Dialog
看看演示
- Official Page
- Examples
获得数据后,在 onPostExecute(...)
View
编辑:
//Progress Dialog Show logic here
Runnable r=new Runnable() {
@Override
public void run() {
//Dismiss the Dialog and refresh your Views
}
};
new Handler().postDelayed(r,10*1000);
此代码在 10 秒后执行
如果您不在新线程上执行任何操作,则不需要处理程序。只需调用如下方法:
private void updateView(ProgressDialog dialog){
//UPDATE
if(dialog != null){
dialog.dismiss();
}
}