Reputation: 83
I have a very small problem and which probably going to be easy for somebody with better knowledge than me but I have a problem with my alertDialog
and the issue that when I write the code for the dialog to be dismiss under the set button method. It gives me an syntax error and I have trying to figure out why for hours and I cant get around this simple problem. Can somebody assist me with this issue.
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("ApplicationTitle");
alertDialog.setMessage("1st line" + "2nd line");
alertDialog.setMessage("1st line" + "2nd line");
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
alertDialog.dismiss();
}
});
alertDialog.show();
this is the line of code I am talking about alertDialog.dismiss();
Upvotes: 0
Views: 71
Reputation:
You almost got it. Just use dialog.cancel();
instead of alertDialog.dismiss();
.
EDIT
You wanted the text to be in different lines. Why don't you try this and tell me if it works:
StringBuilder build = new StringBuilder();
build.append("1st line")
.append("\n")
.append("2nd line")
.append("\n")
.append("3rd line");
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("ApplicationTitle");
alertDialog.setMessage(build.toString());
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
Upvotes: 1