I would like to write a function that displays a warning dialog that returns a boolean based on the button pressed
private Boolean ShowWarningMessageBox(String Title, String message) { boolean returnValue = false; AlertDialog.Builder builder = new AlertDialog.Builder( getApplicationContext()); builder.setTitle(Title); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { returnValue = true; } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); returnValue = false; } }); builder.show(); return returnValue; }
I wrote the above function, but the problem is that the Inner class will not be able to access the returnValue variable, since it is not final. But to make this final is not my purpose.
I am a C # developer and I am trying to achieve something like android
private DialogResult ShowWarningMessageBox(string errorMessage) { DialogResult result = MessageBox.Show(errorMessage, Resources.WarningCaption.ToString(), MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); return result; }
Any help would be appreciated
source share