Problem description
In Android development, this is the case when you use TextView to set a newline:
1. If you write "aaaaa\nbbbb" directly in the XML file, you can wrap it, and display it as:
Aaaaa
bbbbb
2, in the Java file with Textviewobj.settext ("AAAA\NBBBB") can also be wrapped, shown as:
Aaaaa
bbbbb
3. When "AAAAA\NBBBB" is encapsulated in a property of a string type in a class, use Textview.settext (the object name of the class) in Java code. Shown as:
aaaaa\nbbbb
The 3rd above is the problem, not the normal line-wrapping.
Problem Analysis:
Very simply, when the program is running to show "AAAA\NBBBB", then you must set the TextView "AAAA\\NBBBB",
There is a "\" Here, the escape of the string that the object carries has been eliminated,
After passing an object in the following way, if the object contains a string member variable, the escape character contained in the string is invalidated. Because Android is already in the hands and feet of the delivery.
Intent.putextra (extra_object,people);
For example, passing a People object, which has a member variable description that describes the people in detail,
And this description member, which is a string containing the "\ n" escape character, when it is passed,
Its escape character "\ n" has become "\\n",
So, what we're going to do is, after the object is passed, convert it over.
People people= (People) Intent.getserializableextra (Extra_object);
String temp = people.getdescription (). Replace ("\\n", "\ n");
People.setdescription (temp);
This way, then put on the TextView, you can normally display the line break.
Android line break (\ n) shows an unhealthy problem in TextView