In this tutorial, we show you how to create a simple “hello world” Android project in Eclipse IDE + ADT plugin, and run it with Android Virtual Device (AVD).
The Eclipse ADT plugin provided easy Android project creation and
management, components drag and drop, auto-complete and many useful
features to speed up your Android development cycles.
Summary steps to develop an Android application :
- Install Android SDK
- Install ADT Eclipse plugin
- Create an Android Virtual Device (AVD)
- Create Android Project with Eclipse (Wizard)
- Code it…
- Start it in Android Virtual Device (AVD)
Tools used in this tutorial :
- JDK 1.6
- Eclipse IDE 3.7 , Indigo
- Android SDK
1. Install Android SDK
Visit this Android SDK page, choose which platform and install it.
In Android SDK installed folder, run “Android SDK manager”, choose what Android version you want to develop.
2. Install ADT Eclipse plugin
To integrate Android SDK with Eclipse IDE, you need to install Eclipse ADT plugin. Refer to this official guide – “Installing the ADT Plugin“.In Eclipse IDE, select “Help” -> Install New Software…”, and put below URL :
https://dl-ssl.google.com/android/eclipse/
3. Create an Android Virtual Device (AVD)
In Eclipse, you can access the “Android Virtual Device (AVD)” in Eclipse toolbar. Click “new” to create a AVD.4. Create Android Project
In Eclipse, select “File -> New -> Project….”, “Android Project”, and input your application detail. Eclipse will create all the necessary Android project files and configuration.5. Hello World
Locate the generated activity file, and modify a bit to output a string “Hello World”.File : HelloWorldActivity.java
package com.mkyong.android; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloWorldActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView text = new TextView(this); text.setText("Hello World, Android - mkyong.com"); setContentView(text); } }
6. Demo
Run it as “Android Application“, see output.
A program to
demonstrate usage of EditText, Textview and Button widgets in android
this program is very useful for beginners and give the basic overview on
how to use the Api's, using Droiddraw i was able to design the User
Interface with two textbox(EditText) and Label(TextView) and button as
shown in below Pic
below is the XML for above UI generated from DroidDraw
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget35"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<EditText
android:id="@+id/txtbox1"
android:layout_width="145px"
android:layout_height="40px"
android:text="EditText"
android:textSize="18sp"
android:layout_x="75px"
android:layout_y="54px"
>
</EditText>
<EditText
android:id="@+id/txtbox2"
android:layout_width="144px"
android:layout_height="40px"
android:text="EditText"
android:textSize="18sp"
android:layout_x="75px"
android:layout_y="109px"
>
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="106px"
android:layout_height="36px"
android:text="Button"
android:layout_x="88px"
android:layout_y="224px"
>
</Button>
<TextView
android:id="@+id/lbl1"
android:layout_width="141px"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_x="76px"
android:layout_y="166px"
>
</TextView>
</AbsoluteLayout>
<AbsoluteLayout
android:id="@+id/widget35"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<EditText
android:id="@+id/txtbox1"
android:layout_width="145px"
android:layout_height="40px"
android:text="EditText"
android:textSize="18sp"
android:layout_x="75px"
android:layout_y="54px"
>
</EditText>
<EditText
android:id="@+id/txtbox2"
android:layout_width="144px"
android:layout_height="40px"
android:text="EditText"
android:textSize="18sp"
android:layout_x="75px"
android:layout_y="109px"
>
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="106px"
android:layout_height="36px"
android:text="Button"
android:layout_x="88px"
android:layout_y="224px"
>
</Button>
<TextView
android:id="@+id/lbl1"
android:layout_width="141px"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_x="76px"
android:layout_y="166px"
>
</TextView>
</AbsoluteLayout>
and below is the Java Source code which contains the logic to add two numbers and the refrence to id of the controls can be found in above XML
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class fit extends Activity {
Button button1;
EditText txtbox1,txtbox2;
TextView tv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtbox1= (EditText) findViewById(R.id.txtbox1);
button1 = (Button) findViewById(R.id.button1);
tv = (TextView) findViewById(R.id.lbl1);
txtbox2= (EditText) findViewById(R.id.txtbox2);
button1.setOnClickListener(new clicker());
}
class clicker implements Button.OnClickListener
{
public void onClick(View v)
{
String a,b;
Integer vis;
a = txtbox1.getText().toString();
b = txtbox2.getText().toString();
vis = Integer.parseInt(a)+Integer.parseInt(b);
tv.setText(vis.toString());
}
}
}
I moorthy anna .I'm Rakesh who completed my BE(ECE). I want to learn Android so that i need to learn Java also. so,please prefer me some websites to learn java ....
ReplyDeleteI've another doubt also. If i start with Android.How good my future will be?
Please Reply Anna .
Just follow my blog "moorjava.blogspot.in" to learn java, this will be easy to learn.In future everyone will use android smart phones and so many vacancies are there,so there is no worry....if u have doubts on android u can make comment..and all the best my friend...
ReplyDeletegreat dude!
ReplyDeleteMoorthy nu soldranga,
ReplyDeleteI just want to have some basics concepts and codes in snapshot basis in android and want to prepare for an interview , kindly let me know what are the questions may ask while attending an interview and myself working for SYsunivers as developer , i am looking for an opportunity in iphone or wndroid since i have basic knowledge in java and good knoledge in c and c++ and also going for class on android&iphone.
let me know a overview please!
already i have question and answers in my blog kindly follow this link http://moorandroid.blogspot.in/ u can download it under "download source".
ReplyDeleteThanks for your valuable comment.