androidapiandroid-json

Setting a new line from API call not creating newline


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


Solution

  • String description = userInfo.getDescription();
    description = description.replace("\\n", System.lineSeparator());
    System.out.println(description);
    mTextView.setText(description);