Skip to content

Instantly share code, notes, and snippets.

@pyadav
Forked from guptasanchit90/DestructiveDialog.java
Created August 8, 2016 03:40
Show Gist options
  • Select an option

  • Save pyadav/a23a8e60972612f3d88c9d492e7616b6 to your computer and use it in GitHub Desktop.

Select an option

Save pyadav/a23a8e60972612f3d88c9d492e7616b6 to your computer and use it in GitHub Desktop.
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
/**
* Dialog helper class
*/
public class DestructiveDialog {
public DestructiveDialog(Context context, String title, String message, String positive, String negative, final DialogListener dialogListener) {
AlertDialog alertDialog = new AlertDialog.Builder(
context)
.setPositiveButton(positive, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (dialogListener != null) {
dialogListener.onDialogEvent(true);
}
}
})
.setNegativeButton(negative, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (dialogListener != null) {
dialogListener.onDialogEvent(false);
}
}
})
.setTitle(title)
.setMessage(message)
.create();
alertDialog.show();
}
public interface DialogListener {
void onDialogEvent(boolean action);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment