I need to display multiple lines of messages, rather than just one paragraph, in an alert dialogue.
new AlertDialog.Builder(this)
.setTitle("Place")
.setMessage("Go there" +
"Go here")
.setNeutralButton("Go Back", null)
.show();
Is there a way to start at new lines? Just like hitting enter after a sentence in Microsoft Word?
No guarantees on this, but usually to do multiple lines you do something like:
.setMessage("Go there\nGo here");
The "\n" is an escape character that means "New Line" I don't know about your specific case, but you can use it in just about everything AFAIK.
Use the "\n" tag in your strings:
new AlertDialog.Builder(this)
.setTitle("Place")
.setMessage("Go there" + "\n" +
"Go here")
.setNeutralButton("Go Back", null)
.show();
Have you tried a carriage return or line feed character? These are characters 10 and 13 respectively (special characters \n and \r, or \u000a and \u000d)
I think the best solution is to avoid break line and use a custom view component.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
TextView tw =new TextView(this);
tw.setMaxLines(10);
tw.setPadding(3,3,3,3);
tw.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
tw.setSingleLine(false);
tw.setText("ver long messagge \n with break line \n");
builder.setView(tw);
With this solution you can break the line if you want using \n
, but if you don't, the text will be wrapped on multiple lines (since I set tw.setSingleLine(false);
).