views:

72

answers:

1

Hello I have a bunch of text on my file which i display. I used the Hello World demo to insert this text. Now Whenever i try to edit main.xml it doesn't happen. If anybody knows why that would be cool but I want to know how to add simple scrolling to my text. I don't think I need to use main.xml right. Is there a way I can just add it to my project?

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;


public class manifesto extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //Make a new text view passing Activity object
    TextView tv = new TextView(this);
    //Set a text into view

    tv.setText("A bunch of text.");
    tv.setTextSize(12);

    //set the view into activity view container
    setContentView(tv);    
    }
}    

Here is the XML file in case you want to see it.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"&gt;

<TextView android:text="@+id/TextView01" 
android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:id="@string/hello"></TextView>                        

 </LinearLayout>
A: 

First off, you're calling setContentView(tv), so you're not actually seeing any Views from the XML, only the TextView you initialized in onCreate(). Also, it looks like you've got your android:text and android:id attributes mixed up in your XML. It should be

<TextView android:id="@+id/TextView01" 
  android:layout_width="wrap_content" android:layout_height="wrap_content" 
  android:text="@string/hello" /> 

And for your question on scrolling, see http://stackoverflow.com/questions/1748977/making-textview-scrollable-in-android.

cfei
OK I deleted everything in the project and just transferred everything under the main.xml. It doesn't show up now. What am I doing wrong? I Deleted all of this code TextView tv = new TextView(this); //Set a text into view tv.setText("A bunch of text."); tv.setTextSize(12); //set the view into activity view container setContentView(tv); }} and added my bunch of text into main.xml under <TextView android:id="@+id/TextView01" AndroidText="a bunch of text." and then all the normal stuff what am i doing wrong?
Make sure it's `android:text`, not AndroidText. Otherwise, I don't know what's wrong, you haven't posted enough code for me to tell.
cfei
That's all the code i have it's a very simple project i just want to display a bunch of text and have it scroll. Using the basic Hello World app demo.
Sorry i restarted the program and I didnt edit the java file just main.xml and it worked!!!!