Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert a new line in strings in Android

This may seem like a stupid question, but I've been searching and can't find an answer.

I'm creating an android application and within it there is a button that will send some information in an email, and I don't want to have everything all in one paragraph.

Here's what my app is doing for the putExtra for the email's body:

I am the first part of the info being emailed. I am the second part. I am the third part. 

Here's what I want it to do:

I am the first part of the info being emailed. I am the second part.  I am the third part. 

How would I put a new line into a string or with the putExtra method to accomplish that?

Thank you.

like image 234
Reed Avatar asked Jun 16 '11 23:06

Reed


People also ask

How do I add a line break in Android?

Add Line Breaks to a TextView Just add a \n to your text. This can be done directly in your layout file, or in a string resource and will cleanly break the text in your TextView to the next line.

How do I add a new line to a string?

In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.

How do you put line through text on Android?

If you want to show a strike-through text you can do it programming using PaintFlags. You can set paint flags Paint. STRIKE_THRU_TEXT_FLAG to a TextView and it will add a strike-through to the text. TextView textView = (TextView) findViewById(R.

Does \n work in a string?

in a string prevents actually making a new line and instead of Type (new line) for a new line it is Type \n for a new line .


1 Answers

Try:

String str = "my string \n my other string"; 

When printed you will get:

my string
my other string

like image 115
user824013 Avatar answered Sep 23 '22 16:09

user824013