3

How to make a new line after every text??

This's the code.

String body = txtName.getText().toString() + txtLatitude.getText().toString() + txtLongitude.getText().toString();
ii.putExtra(android.content.Intent.EXTRA_TEXT, body);

I tried to use only \n but it's giving me error. Please help me.

Renjith
  • 5,783
  • 9
  • 31
  • 42
user1673210
  • 73
  • 1
  • 2
  • 6

3 Answers3

5
String body = txtName.getText().toString() + "\n" + txtLatitude.getText().toString() + "\n" + txtLongitude.getText().toString();
Mr.Sandy
  • 4,299
  • 3
  • 31
  • 54
Krauxe
  • 6,058
  • 2
  • 24
  • 22
1

You can use html tag in your string like this.

String body = Html.fromHtml(txtName.getText().toString()+"<br />"
                    + txtLatitude.getText().toString()+"<br />"
                    + txtLongitude.getText().toString()+"<br />");
androidcodehunter
  • 21,567
  • 19
  • 47
  • 70
0

I take it you are using android java. Unsure, but in c++ you can use the endl function in std library. I think there is a similar function, system.getproperty("line.separator") or ("line.new") you could try it, It is something close to this. Also Since "\n" doesn't work, try single quotes '\n' it is a newline character so it might count as a single character in java. Other than that
can also work it is standard HTML.

Marcel De Villiers
  • 1,682
  • 4
  • 15
  • 17