Hello World Again

In this section, you will create another Hello World! application for Android. However, this time you will program the UI in code rather than by using the xml fileā€”and you will actually do most of the work. The first step here is to remove the TextView code that is in main.xml. The following section of code represents the TextView. Removing it essentially makes your application an empty shell.

<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World, HelloWorldText"

After you have removed the TextView code, your main.xml file should look like this:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation="vertical" android:layout_width="fill_parent"

android:layout_height="fill_parent" >

</LinearLayout>

Now that you have a clean main.xml file, and thus a clean application shell, you can begin to add the code that will display "Hello World!" on the screen. Start by opening the HelloWorldText.java file and removing the following line:

setContentView(R.layout.main);

0 0

Post a comment