I've created a class to make it easier to use Dialogs, and I'd like to know if you can simplify it even further.
My Class looks like this:
public class FVRDialog {
private Activity act;
private Context context;
private AlertDialog dialog;
public FVRDialog(Activity act) {
this.act = act;
}
public boolean Confirm(int icon, String Title, String ConfirmText,
String OkBtn, String CancelBtn, final Runnable OkBtnPress, final Runnable CancelBtnPress) {
dialog = new AlertDialog.Builder(act).create();
dialog.setTitle(Title);
dialog.setMessage(ConfirmText);
dialog.setCancelable(false);
if (icon != 0) { dialog.setIcon(icon); }
dialog.setButton(DialogInterface.BUTTON_POSITIVE, OkBtn,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int buttonId) {
OkBtnPress.run();
}
});
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, CancelBtn,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int buttonId) {
CancelBtnPress.run();
}
});
dialog.show();
return true;
}
public void dismiss() {
dialog.dismiss();
}
}
And to execute I'm doing so:
final FVRDialogs fvrdialog = new FVRDialogs(this);
fvrdialog.Confirm(@drawable/ic_pergunta, "Titulo", "Descrição", "Sim","Não",
new Runnable() { public void run() { executarBtnSim(); } },
new Runnable() { public void run() { executarBtnNao(); } });
I would like to simplify without having to use runnable, leave it as possible, more or less like this:
FVRDialogs fvrdialog = new FVRDialogs(this);
fvrdialog.Confirm(@drawable/ic_pergunta, "Titulo", "Descrição", "Sim","Não", executarBtnSim(), executarBtnNao());
Or if you have some other interesting way to do this, I'm open to suggestions.