要去除AlertDialog彈窗,你可以使用以下方法之一:
dialog.dismiss()
方法關閉彈窗。AlertDialog dialog = new AlertDialog.Builder(context)
.setTitle("Title")
.setMessage("Message")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Handle click event
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Handle click event
}
})
.create();
dialog.show();
// 關閉彈窗
dialog.dismiss();
dialog.hide()
方法。AlertDialog dialog = new AlertDialog.Builder(context)
.setTitle("Title")
.setMessage("Message")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Handle click event
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Handle click event
}
})
.create();
dialog.show();
// 隱藏彈窗
dialog.hide();
請注意,這些方法只是隱藏或關閉彈窗,并不會銷毀AlertDialog對象。如果你想完全銷毀AlertDialog對象,可以調用dialog = null;
來釋放內存。