Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class AlertWrapper {
public static void getConfirmDialog(Activity activity,
String title,
String message,
String positiveButtonText,
String negativeButtonText,
Boolean cancellable,
final AlertInterface target) {
if (!activity.isFinishing()) {
android.support.v7.app.AlertDialog.Builder dialog = new android.support.v7.app.AlertDialog.Builder(activity,
R.style.ThemeDialogCustom).setMessage(message)
.setPositiveButton(positiveButtonText,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
target.PositiveMethod(dialog,
which);
}
})
.setCancelable(cancellable);
if (!TextUtils.isEmpty(title)) {
dialog.setTitle(title);
}
if (!TextUtils.isEmpty(negativeButtonText)) {
dialog.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
target.NegativeMethod(dialog, which);
}
});
}
AlertDialog alertDialog = dialog.create();
alertDialog.show();
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.BLACK);
}
}
public interface AlertInterface {
void PositiveMethod(DialogInterface dialog, int id);
void NegativeMethod(DialogInterface dialog, int id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.