Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8523843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:31:33+00:00 2026-06-11T07:31:33+00:00

I’m creating a custom view programmatically that is displaying text that is parsed from

  • 0

I’m creating a custom view programmatically that is displaying text that is parsed from an XML file. The text is long and contains the “/n” character for force line breaks. For some reason, the text view is displaying the /n and there isn’t any line breaks. Here is my code:

                    // get the first section body
                    Object body1 = tempDict.get("FIRE");
                    String fireText = body1.toString();

                    // create the section body
                    TextView fireBody = new TextView(getActivity());
                    fireBody.setTextColor(getResources().getColor(R.color.black));
                    fireBody.setText(fireText);
                    fireBody.setTextSize(14);
                    fireBody.setSingleLine(false);
                    fireBody.setMaxLines(20);
                    fireBody.setBackgroundColor(getResources().getColor(R.color.white));

                    // set the margins and add to view
                    layoutParams.setMargins(10, 0, 10, 0);
                    childView.addView(fireBody,layoutParams);

The text from the XML file is like this:

Now is the time /n for all good men to /n come to the aid of their /n party

It should display as such;

Now is the time
for all good men to
come to the aid of their
party

Is there are setting that I’m missing?

UPDATE

\r\n works if I hard code it into my view. ie:

String fireText = "Now is the time \r\n for all good men \r\n to come to the aid";

Actually \n also works if i hard code it:

String fireText = "Line one\nLine two\nLine three";

FYI

System.getProperty("line.separator");

this returns a string of “/n” so there is no need to convert to “/r/n”.

Unfortunately, my data originates in a XML file that is parsed and stored in a hashmap. I tried the following:

String fireText = body1.toString().replaceAll("\n", "\r\n");

The \n is not getting replaced with \r\n. Could it be because I’m converting from an object to String?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:31:35+00:00Added an answer on June 11, 2026 at 7:31 am

    I’ve been having the exact same problem under the exact same circumstances. The solution is fairly straight forward.

    When you think about it, since the textview widget is displaying the text with the literal “\n” values, then the string that it is being given must be storing each “\n” like “\\n”. So, when your XML string is read and stored, all occurrences of “\n” are being escaped to preserve that text as literal text.

    Anyway, all you need to do is:

    fireBody.setText(fireText.replace("\\n", "\n"));
    

    Works for me!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
For some reason, after submitting a string like this Jack’s Spindle from a text
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a bunch of posts stored in text files formatted in yaml/textile (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.