如何在进度对话框中设置取消按钮? [英] How to set a cancel button in Progress Dialog?
本文介绍了如何在进度对话框中设置取消按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的ProgressDialog
中设置一个取消按钮.下面是我的代码:
I want to set a cancel button in my ProgressDialog
. Below is my code:
myDialog = new ProgressDialog(BaseScreen.this);
myDialog.setMessage("Loading...");
myDialog.setCancelable(false);
myDialog.show();
我想在此ProgressDialog
上设置带有onClickListener
的按钮.
我尝试使用以下代码:
I want to set a button with an onClickListener
on this ProgressDialog
.
I tried with this code:
myDialog.setButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
myDialog.dismiss();
}
});
但是它不起作用.我也尝试过其他类似的听众,但仍然没有成功. 我该如何解决这个问题?
But it isn't working. I tried other similar listeners also, but still no success. How can I solve this problem?
推荐答案
已弃用您正在使用的setButton
方法(尽管它仍然可以使用).另外,您可能想要添加之前按钮来显示对话框.试试:
The setButton
method you are using is deprecated (although it should still work). Also, you might want to add the button before showing the dialog. Try:
myDialog = new ProgressDialog(BaseScreen.this);
myDialog.setMessage("Loading...");
myDialog.setCancelable(false);
myDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
myDialog.dismiss();//dismiss dialog
}
});
myDialog.show();
这篇关于如何在进度对话框中设置取消按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文