1

I am working on an E-mail Application where I have to send and receive and also have to display email in TextView when ever user wants to read it

This is the feed I am getting from API :-

 {
    "messages":   
    [{"id":"136902",
"from":"Akash",
"email":"akash@email.com",
"subject":"mail App!!",
"message":"Hi Devraj,\n\n \n\nKindly provide sabmail apk for google  play store.\n\n \n\nRegards,\n\nAkash",
"date":"1448870780",
"userid":"75",
"recipients":"devraj@mail.com ",
"status":"0",
"isread":"1",
"priority":"3",
"size":"3057"}
]}

I am taking the "message" tag and displaying it in TextView. It looks like this

Hi Devraj,Kindly provide mail apk for google play store.Regards,Akash,

But, I want it to be look like this,

Hi Devraj,

Kindly provide mail apk for google play store.

Regards,

Akash,

How can I do achieve this.

This is the way I am setting it in TextView

String msg = messageDisc.getMessage();

Spanned sp = Html.fromHtml(msg);

emailText.setText(sp);
emailText.setMovementMethod(LinkMovementMethod.getInstance());

Please let me know what mistake I am doing here.

AnswerDroid
  • 1,873
  • 2
  • 33
  • 52
Devraj
  • 1,479
  • 1
  • 22
  • 42
  • Your `message` tag doesn't really look like Html from the feed you posted., or am I wrong..? – yennsarah Dec 01 '15 at 08:25
  • Try one of the solutions suggested on http://stackoverflow.com/questions/5382490/how-to-add-a-line-break-in-an-android-textview – Sameer Awate Dec 01 '15 at 08:28

3 Answers3

2

Try to replace: \n with <br>.

String msg = messageDisc.getMessage();
msg = msg.replace("\n", "<br>");
Spanned sp = Html.fromHtml(msg);
AnswerDroid
  • 1,873
  • 2
  • 33
  • 52
  • hello AnswerDroid, Thanks for your response. please let me know what is this ..... msg = msg.replace("\n", " ") do u want me to hit enter Key for this or just spacebar? – Devraj Dec 01 '15 at 08:26
  • msg = msg.replace("\n", "
    "); just type this since
    will give that space
    – AnswerDroid Dec 01 '15 at 08:28
  • @Aspicas yes.. it did work like charm.. :D. just give me 2 minutes as it takes minimum 2 minutes to accept any answer.. :P – Devraj Dec 01 '15 at 08:32
1

Supply android:maxLines="<any number>" to the TextView. So that \n will work.

Aspicas
  • 4,498
  • 4
  • 30
  • 53
Ajitha
  • 717
  • 1
  • 7
  • 30
-1

first parse the json data and stored it into a different String.

Then set the String object to the edittext by seperating it with a \n line.

eg: emailText.setText(sp+"" +\n+""+obj);

Mauker
  • 11,237
  • 7
  • 58
  • 76