I have a method:
void someMethod(String someString)
final String[] testAgainst = {...};
....
for(int i = 0; i < testAgainst.length; i++) {
if (someString.equals(testAgainst[i])) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Strings are the same! Overwrite?")
.setTitle("Blah Blah Blah")
.setCancelable(false)
.setPositiveButton("Overwrite", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface di, int which) {
someAction()
}
})
.setNegativeButton("Nah", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface di, int which) {
ESCAPE
}
});
AlertDialog dialog = builder.create();
}
}
doSomeOtherStuff();
}
Here's the thing, if my code reaches ESCAPE
(that is, the user decides not to overwrite), I want to exit the method completely. I have tried...
- changing
someMethod()
to return a boolean, then returning it from the negative button, but it won't let me because it's within a void internal method. - throwing an exception from
ESCAPE
to be caught externally, but the compiler won't let me becauseDialogInterface.OnClickListener
doesn't throw. - using a
break
statement to leave thefor
loop, but that doesn't work either.
It would also be acceptable to simply leave the for
loop. I can account for that. I've tried everything I can find and I'm at my wit's end.