Finally I created my firstĀ “HelloWorld” app in Android and I am sharing it with you. This is just a simple HelloWorld Program that displays a HelloWorld in a Button with Date and Time on it. The date and time changes with the click on the button. I have tried to implement actionlisteners so it is little more than a HelloWorld Program.
Steps to Create My HelloWorld Program in Eclipse with Android SDK. Create a new android project. File->New->Android Project. Fill in information like Project Name, Location for your project (e.g. Create new project in workspace). Select build Target. Android has several Versions ranging from 1.1 to 2.0 (latest). Select the target platform you want to port your application to. I selected 1.5 and it depends on you. Enter Application Name, Package name, Activity Name and hit finish button. In my case I entered following information for my first HelloWorld Program.
ProjectName: HelloWorld
Location for your project: /home/sanjeev/androidworkspace/HelloWorld
Select Build Target: Android 1.5
Application Name: HelloWorld
Package Name: com.sanjeevshrestha.android
Activity Name: HelloWorld
This creates a project in your workspace and you are ready to modify the activity file that is HelloWorld.java which is in your src folder under the folder structure depending on your package name. In my case it is src/com/sanjeevshrestha/android/HelloWorld.java. Here is the content of my HelloWorld.java file
/**
* Hello World Program
* @author Sanjeev Shrestha
* @version 1.0
* @date 8 November 2009
*
*/package com.sanjeevshrestha.android;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.Date;public class HelloWorld extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
btn=new Button(this);
btn.setOnClickListener(this);
updateTime();
setContentView(btn);
}public void onClick(View view)
{
updateTime();
}public void updateTime()
{
String DateString=new Date().toString();
btn.setText(“Hello World by Sanjeev at “+DateString);
}
}
Build the project and your first HelloWorld program is ready for Android. Here is the output of my HelloWorld Program.


My First Android HelloWorld Program. I am loving it ![]()
Try for yourself and Happy Androiding!!
Download the zip file for HelloWorld application HelloWorld

Tags: android, First Program, Hello World in Android, HelloWorld