Wednesday 25 January 2012

Writing Hello World Program using Eclipse and creating the environment for Android Development

Here is the complete steps to create and setup environment for android application development and writing a sample android application below are the easy step by step guide.


Step1: Downloading required packages
To download Ecliplse visit the web sithttp://www.springsource.com/products/eclipse-downloads
Download Google Android SDK from http://developer.android.com/sdk/index.html

Step 2:Unpacking Downloaded Files
Unpack Eclipse and SDK in your desired location. Now open the eclipse folder and click on Eclipse icon to start.

Step 3:Setting up your Eclipse
Check Internet connection.Now,Go to HELP from menu ,click on “Check for updates”. 

Step 4:Setting up your ADT
a. Go to  HELP from menu ,click on “Install new software”.Click on add,
Name : ADT Plugins
then press OK.Now, Select “DEVELOPMENT TOOLS” press next.It will download all the Tools.
b. Restart the Eclipse.

Step5: Now we have to point the Eclipse to the Android SDK Directory you downloaded
a. In eclipse select window-->Prefrences and select "Android" in prefrence window
b. Now find the Browse button as shown in Above Pic and point it to downloaded SDK directory and click on apply and ok as shown in above PIC
c. Restart Eclipse
Now your Environment is ready to start your first Android application.

Creating the Sample Android Project to display the Hello World.

1. In Eclipse select menu File-->New-->Project
2. Select Android Project" .

3.  Now Select the sdk version from the list and click on Next.



4. Enter your project name HelloWorld then enter the package name .The package name is very important for your application . Click on finish.


  5.Go to package explorer and open the "HelloworldActivity.java" file.You will see the auto generated code by Eclipse.
HelloworldActivity.java
------------------------------------------------------------------------------------------------------------------------------
package com.sourav.helloworld;

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

public class HelloworldActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}


----------------------------------------------------------------------------------------------------------------------------------
Now go to  --  rec ->layout -> main.xml

main.xml
----------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
</LinearLayout>


----------------------------------------------------------------------------------------------------------------------------------
the TextView have a property android:text="@string/hello".This text is declared in string.xml file,inside values folder. 



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


<resources>
    <string name="hello">Hello World, HelloworldActivity!</string>
    <string name="app_name">Helloworld</string>
</resources>


----------------------------------------------------------------------------------------------------------------------------------

So,your code is ready .Now it's time to create a AVD(Android Virtual Device).Select and create the AVD and start the virtual device .

now Click on Run and select your application .you will see the " hello world,HelloWorldActivity" text appearing on the screen . 
















Enjoy.... 
Do post your doubts, queries or suggestions in this blog.

No comments:

Post a Comment