Created
March 14, 2018 10:30
-
-
Save parthitechnotion/8169acda1d45bced262c0ea41cb887a0 to your computer and use it in GitHub Desktop.
Alert dialog from Utils
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
// Put this in your actvity or fragment | |
ViewUtils.showConfirm("Are you sure you want to logout?", getActivity(), new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
AppSetting.getCurrent().clearLogin(); | |
App.showLogin(getActivity()); | |
} | |
}, null); | |
---------------------------------------------- | |
// Put this in your | |
---------------------------------------------- | |
public static AlertDialog showConfirm(String message, Context context, final DialogInterface.OnClickListener okClickListener, final DialogInterface.OnClickListener cancelClickListener) | |
{ | |
TextView msgView = new TextView(context); | |
msgView.setText(message); | |
msgView.setTextSize(18); | |
msgView.setPadding(10,10,10,10); | |
msgView.setGravity(Gravity.CENTER); | |
msgView.setTextColor(Color.BLACK); | |
AlertDialog.Builder builder = new AlertDialog.Builder(context); | |
builder.setView(msgView) | |
.setCancelable(false) | |
.setPositiveButton("OK", new DialogInterface.OnClickListener() { | |
public void onClick(DialogInterface dialog, int id) { | |
if (okClickListener != null) | |
okClickListener.onClick(dialog, id); | |
dialog.dismiss(); | |
} | |
}) | |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int i) { | |
if (cancelClickListener != null) | |
cancelClickListener.onClick(dialog, i); | |
dialog.dismiss(); | |
} | |
}); | |
AlertDialog alert = builder.create(); | |
alert.show(); | |
Button nbutton = alert.getButton(DialogInterface.BUTTON_POSITIVE); | |
nbutton.setTextColor(Color.BLACK); | |
return alert; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment