Created
October 3, 2016 15:32
-
-
Save mustafasevgi/b04837d91be0d385abd6f5be730dd0c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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