Android Hello world Program

November 15th, 2011 by aabhaanjan

Android Hello world Program :
Lets start with hello world program. Here we will learn how to write
a hello world program in android :
Step 1 :Create New android Project.

1

Step 2 :Give the Project Name and choose SDK version.

2

Step 3 :The manifest file.

3

step 4 : Here is code :

Code of used classes :
Activity Class :
[xml]
package com.helloworldandroid;

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

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText(“Hi This is your first Program”);
setContentView(tv);
}
}
[/xml]

R.Java :
[xml]
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/

package com.helloworldandroid;

public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}

[/xml]

res/layput/main.xml :
[xml]
<?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”
>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello”
/>
</LinearLayout>
[/xml]
Step 5 : Run your application :- It will look like this
4

Tags: , , , , , ,