Skip to content

Instantly share code, notes, and snippets.

@guptasanchit90
Last active August 8, 2016 03:40
Show Gist options
  • Save guptasanchit90/dab4bd5850bc2aafc002 to your computer and use it in GitHub Desktop.
Save guptasanchit90/dab4bd5850bc2aafc002 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