Note

You still need to set a ContentView for your new application; however, you are going to implement it slightly differently from how it is implemented here, so it is best to just remove the entire statement for now.

This line uses setContentView( ) to draw the main.xml file to the screen. Since you will not be using main.xml to define your TextView, you will not be setting it to your view. Instead, you will be building the TextView in code.

Your next step is to import the package TextView from android.widget. This will give you access to the TextView and let you create your own instance of it. Place this code near the top of your current HelloWorldText.java file, where the existing import statements are import android.widget.TextView;

Now, create an instance of TextView. By creating the TextView instance, you can use it to display text to the screen without directly modifying main.xml. Place the following code after the onCreate( ) statement is fired:

TextView HelloWorldTextView = new TextView(this);

0 0

Post a comment