AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.atention));
builder.setNegativeButton(android.R.string.cancel, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// On "Cancel" clicked functionality
}
});
builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// On "Accept" clicked functionality
}
});
builder.setMessage(getString(R.string.are_you_sure_you_want_to_quit));
AlertDialog alert = builder.create();
/* The dialog will be dismissed when the user touches outside of it */
alert.setCanceledOnTouchOutside(true);
alert.show();
If you wanted to prevent the dialog to be dismissed previous to some condition we would have to:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
...
builder.setPositiveButton(android.R.string.ok, null);
...
final AlertDialog alert = builder.create();
alert.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button possitiveButton = alert.getButton(AlertDialog.BUTTON_POSITIVE);
possitiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// If the conditions is fullfilled you should call: alert.dimiss();
// else do whatever you need to do
}
});
...
No hay comentarios:
Publicar un comentario