I am building an app that include the c++ programs. I just need to show the code as a text in my xml layout. I don’t want it to compile it or to do anything else with it. But every time i write the text it show error that you cant use strings like ‘<‘, ‘>’ or double inverted commas. Can you please help me out how i can use these strings in my text view.
Here is my xm layout.
<?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" >
<EditText
android:id="@+id/program_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:text="
#include<iostream.h>
#include<conio.h>
void main()
{
int arr[n], i,j,n,temp;
cout<<"How any elements you want to enter";
cin>>n;
cout<<"Enter array elements"
for(i=0;i<n;i++)
cin>>a[i]
} " >
<requestFocus />
</EditText>
Take a look to my response in this question. You shouldn’t include literal strings in your XML layout. It is much more recommended to store C code in files in assets folder, so you don’t need to modify them at all (it’s a waste of time and a source of errors). Just inflate a WebView widget with all the C code enclosed in
<pre>[text read from file]</pre>tags and you will be able to show it perfectly OK and take advantage of scrolling and zoom for free.