1

Is there any way to display the code by the help of using textview. Here is my problem, when i write the code into android:text=" " of the textview it shows an error.I am just trying to show the code using textview.

Please help me

Error 1(Line 14):String literal is not properly closed by a double-quote

Error 2(line 20):Multiple markers at this line - Illegal modifier for the local class MainActivity; only abstract or final is permitted - The nested type MainActivity cannot hide an enclosing type

Here is my xmlcode:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test.MainActivity"
tools:ignore="MergeRootFrame" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="" />

</FrameLayout>

Here is my Java Code:

package com.example.test;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.widget.TextView;
import com.example.han.R;

public class MainActivity extends ActionBarActivity {
TextView tv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

tv=(TextView) findViewById(R.id.textView1);
tv.setText("package com.example.test;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import com.example.han.R;

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}");
}

}
Sandy
  • 49
  • 4
  • what is the errors? post it. – M D May 20 '14 at 11:14
  • post your code what you have tried.. – Shailendra Madda May 20 '14 at 11:16
  • and what "code" do you want to show in your textView – PKlumpp May 20 '14 at 11:16
  • Check this similar question [Is it possible to have multiple styles inside a TextView?][1] [1]: http://stackoverflow.com/questions/1529068/is-it-possible-to-have-multiple-styles-inside-a-textview – devcfgc May 20 '14 at 11:21
  • maybe you can edit the textview programatically : TextView yourTextView = (TextView) findViewById(R.id.your_text_view_id); yourTextView.setText("what you want in yourTextView"); – Guy S May 20 '14 at 11:22
  • Your error is probably the string that you're trying to put into `android:text=""` is not correctly escaped / formatted. – FunkTheMonk May 20 '14 at 11:35
  • @user2498436 -link you provided is totally different from my concern because I just want to show the code as it is in same format and alignment – Sandy May 21 '14 at 09:59

0 Answers0