1

Setting a new line without a network call works for me:

mTextView.setText("Message 1 \nMessage 2");

enter image description here

However when I set the text from the JSON in an API call it doesn't work for me:

mTextView.setText(userInfo.getDescription());

enter image description here

The format it's stored in my db is: hello \nTest message.

What is the issue?

Edit:

Tried doing this, but doesn't work either

Log.d(TAG, "formatDescription: Description: " + description);
String x = description.replace("\n", System.lineSeparator());
Log.d(TAG, "formatDescription: Formatted: " + x);
return x;

enter image description here

Edit 2:

Need to add an extra "\" to .replace("\n", System.lineSeparator()); for it to work

2 Answers 2

2
String description = userInfo.getDescription();
description = description.replace("\\n", System.lineSeparator());
System.out.println(description);
mTextView.setText(description);
2
  • Have you checked value of x here? What is that?
    – Nik
    Commented Jan 3, 2020 at 10:16
  • Adding an extra "\" to "\n" works. .replace("\\n"
    – DIRTY DAVE
    Commented Jan 3, 2020 at 10:18
0

Try this:

String desc = userInfo.getDescription().replaceAll("\\n", System.getProperty("line.separator"));
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.