我想在我的ProgressDialog
中设置一个取消按钮。下面是我的代码:
myDialog = new ProgressDialog(BaseScreen.this);
myDialog.setMessage("Loading...");
myDialog.setCancelable(false);
myDialog.show();
我想在这个ProgressDialog
上设置一个带有onClickListener
的按钮。我尝试使用以下代码:
myDialog.setButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
myDialog.dismiss();
}
});
但它不起作用。我也尝试了其他类似的听众,但仍然没有成功。我该如何解决这个问题?
发布于 2011-08-12 16:32:03
确保在调用myDialog.show();
之前调用myDialog.setButton
此外,如果您只需要在单击按钮时关闭对话框,则可以使用myDialog.setButton("Cancel", (DialogInterface.OnClickListener) null);
。
发布于 2011-08-12 16:42:13
看看这个
private void createCancelProgressDialog(String title, String message, String buttonText)
{
cancelDialog = new ProgressDialog(this);
cancelDialog.setTitle(title);
cancelDialog.setMessage(message);
cancelDialog.setButton(buttonText, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
// Use either finish() or return() to either close the activity or just the dialog
return;
}
});
cancelDialog.show();
}
然后只需在活动中的其他地方使用一个简单的调用方法
createCancelProgressDialog("Loading", "Please wait while activity is loading", "Cancel");
https://stackoverflow.com/questions/7037433
复制相似问题