Skip to content

Instantly share code, notes, and snippets.

@guptasanchit90
Created September 22, 2016 07:58
Show Gist options
  • Save guptasanchit90/67ce90736e64d9a31863c84e2c9f712a to your computer and use it in GitHub Desktop.
Save guptasanchit90/67ce90736e64d9a31863c84e2c9f712a to your computer and use it in GitHub Desktop.
package module.utilities;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
/**
* Created by sanchit.gupta on 9/22/2016.
*/
public class TwoStateDialog {
private AlertDialog alertDialog;
/**
* @param context - Context
* @param title - Title of dialog
* @param message - Message to show inside the dialog
* @param positive - Text to show on positive button
* @param negative - Text to show on nagative button
* @param dialogListener - A listener to capture user input
*/
public TwoStateDialog(Context context, String title, String message, String positive, String negative, final DialogListener dialogListener) {
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();
}
public void show() {
if (alertDialog != null)
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