Add new line character in string

24,655

Solution 1

String body = txtName.getText().toString() + "\n" + txtLatitude.getText().toString() + "\n" + txtLongitude.getText().toString();

Solution 2

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 />");
Share:
24,655
user1673210
Author by

user1673210

Updated on April 27, 2020

Comments

  • user1673210
    user1673210 about 4 years

    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.