0

My textview contains c++ code. As it contains special characters, i have got all other character included but when i use "\n" in my code, it enters the next line and enters remaining text to next line. How can i resolve it? Also i have included \n in start of every line because i want those lines to start from next line. here is my layout sample:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/string_display"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:text="
\n #include&lt;iostream>
\n #include&lt;conio.h>
\n #include&lt;stdio.h> 
\n void main()
\n {
\n  clrscr();
\n  char a[100];
\n  cout&lt;&lt;&quot;Enter String:&quot;;
\n  cin>>a;
\n  cout&lt;&lt;&quot;String you entered:&quot;;
\n  cout&lt;&lt;a;
\n  getch();
\n }
\n \n 
//using gets function
\n //now it will include spaces
\n
\n #include&lt;iostream.h>
\n #include&lt;conio.h>
\n #include&lt;stdio.h>

\n \n void main()
\n {
\n  clrscr();
\n  char a[100]; 
\n  cout&lt;&lt;&quot;Enter String:&quot;;
\n  gets(a);
\n  cout&lt;&lt;&quot;String you entered:&quot;;
\n  cout&lt;&lt;a;
\n  getch();
\n}

"
android:textSize="20sp" />

</ScrollView>
</LinearLayout>
  • The answer was given here: http://stackoverflow.com/questions/3586763/new-line-character-n-not-displaying-properly-in-textview-android. – Gene Arboit Feb 03 '13 at 19:37
  • But here they have replaced all \n but instead i want to use \n somewhere to start a new line and somewhere not. Any other solution? – user1977768 Feb 03 '13 at 19:44

1 Answers1

0

Simply escape the newline characters that you want displayed with \\n.

Sam
  • 86,580
  • 20
  • 181
  • 179