我有对话框弹出窗口。里面有一个按钮。单击按钮时,将显示确认弹出窗口(是/否)。但问题是对话框弹出窗口关闭了。确认弹出窗口显示时,我不想关闭对话框弹出窗口。我想知道怎么做。在这里我的编码..
Button deleteBtn = (Button) findViewById(R.id.deleteBtn);
deleteBtn.setOnClickListener(new OnClickListener(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose delete tasks");
builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
showMsgDialog();
}
});
private void showMsgDialog() {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
// Setting Dialog Title
alertDialog.setTitle("deleting..");
// Setting Dialog Message
alertDialog.setMessage("Are you sure want to delete?");
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// deleting process.
}
});
alertDialog.show();
}
感谢。
答案 0 :(得分:0)
I don't want to close dialog popup when the confirmation popup show.
AlertDialog
不可能。解决方案:
创建自定义对话框:
private void ShowNoti() {
// TODO Auto-generated method stub
ContextThemeWrapper cw = new ContextThemeWrapper(MainActivity.this,
R.style.AppBaseTheme);
final Dialog dialog = new Dialog(cw);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Choose delete tasks");
// set the custom dialog components - text, image and button
Button dialogButton = (Button) dialog.findViewById(R.id.button1);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// dialog.dismiss();
showMsgDialog_new();
}
});
dialog.show();
}
protected void showMsgDialog_new() {
// TODO Auto-generated method stub
final Dialog dialog = new Dialog(MainActivity.this);
dialog.setContentView(R.layout.custom_new);
dialog.setTitle("delete tasks!");
// set the custom dialog components - text, image and button
Button okButton = (Button) dialog.findViewById(R.id.button1);
// if button is clicked, close the custom dialog
okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// dialog.dismiss();
}
});
Button cancleBtn = (Button) dialog.findViewById(R.id.button12);
// if button is clicked, close the custom dialog
cancleBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// dialog.dismiss();
}
});
dialog.show();
}