This tutorial let’s you develop Android apps on your own on Eclipse IDE with ADT plugin for Eclipse. I’ll describe clearly how to set up an environment for developing Android apps using Eclipse IDE. This tutorial assumes that you already installed Eclipse IDE in your system. Even if you didn’t no problem..you can download from here: http://www.eclipse.org/downloads/. For usage of Eclipse and Eclipse shortcuts you can just refer following link: http://code.techiesteps.com/search/label/Eclipse%20/%20MyEclipse
SETTING UP ANDROID DEVELOPMENT ENVIRONMENT WITH ECLIPSE
Step1: Install Eclipse IDE.
Step2: Android SDK
Download the Android SDK from the Android homepage under Android SDK download . The download contains a zip file which you can extract to any place in your file system, e.g. I placed it under "C:\android-sdk-windows" .
Step3: Use the Eclipse update manager to install all available plugins for the Android Development Tools (ADT) from the URL https://dl-ssl.google.com/android/eclipse/ .
Step3: Configuration
In Eclipse open the Preferences dialog via Windows -> Preferences. Select Android and maintain the installation path of the Android SDK.
Step4: Select now Window -> Android SDK and AVD Manager from the menu.
Step5: Select available packages and select the latest version of the SDK.
Press "Install selected" and confirm the license for all package.
After the installation restart Eclipse.
Step6: Device
You need to define a device which can be used for emulation. Press the device manager button, press "New" and maintain the following.
Press "Create AVD".This will create the device. To test if you setup is correct, Select your device and press "Start".
After (a long time) your device should be started.
To test, whether your device is correctly working or not, search some thing in the Google search if will show results in the Emulator.
ANDROID APPLICATION DEVELOPMENT
Creating First Android Project:
Step1: Select File -> New -> Other -> Android -> Android Project and create the Android project "TemperatureConverter" Maintain the following.
Press "Finish". This should create the following directory structure.
Step2:"R.java" is a generated class which contains the text and the UI elements.
The Android SDK allows to maintain certain artifacts, e.g. strings and UI's, in two ways, via a rich editor and directly via XML. The following description tries to use the rich UI but for validation lists also the XML. You can switch between the two things the the tab on the lower part of the screen. For example:
Step3:Android allows to create attributes for resources, e.g. for strings and / or colors. These attributes can be used in your UI definition via XML or in your Java source code.
Select the file "res/values/string.xml" and press "Add". Select "Color" and maintain "myColor" as the name and "#000099" as the value.
Add also the following "String" attributes. String attributes allow to translate the application at a later point.
| Name | Value |
| buttonHandler | myClickHandler |
| celsius | to Celsius |
| fahrenheit | to Fahrenheit |
please see the xml file whether entries are correctly inserted or not and check for xml validity.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Convert!</string>
<string name="app_name">Celsius to Fahrenheit Converter</string>
<color name="myColor">#000099</color>
<string name="buttonHandler">myClickHandler</string>
<string name="celsius">to Celsius</string>
<string name="fahrenheit">to Fahrenheit</string>
</resources>
Step4: UI Elements
Select "res/layout/main.xml" and open the Android editor via double-click. This editor allows to maintain the UI via drag and drop or directly via the XML source code. You can switch between both representations via the tabs at the bottom of the editor.witch to "main.xml" and verify that your XML looks like the following. Especially the grouping of RadioButtons into a group is difficult to get right with the editor. Delete the "Hello World, Hello!" via a right mouse click. You can add text fields and buttons via rich editor or by placing xml code in main.xml manually. After adding screen 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" android:background="@color/myColor">
<EditText android:id="@+id/EditText01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:inputType="numberSigned|numberDecimal"></EditText>
<RadioGroup android:id="@+id/RadioGroup01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<RadioButton android:id="@+id/RadioButton01"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/celsius" android:checked="true"></RadioButton>
<RadioButton android:id="@+id/RadioButton02"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/fahrenheit"></RadioButton>
</RadioGroup>
<Button android:id="@+id/Button01"
android:layout_height="wrap_content" android:onClick="@string/buttonHandler" android:layout_width="wrap_content" android:text="calculate"></Button>
</LinearLayout>
Step5: Develop logic for converting celsius to Fahrenheit and viceversa write following java code in Convert.java
package org.androidbuzz.apps;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
public class Convert extends Activity { private EditText text;
@Override
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (EditText) findViewById(R.id.EditText01);
}
// This method is called at button click because we assigned the name to the
// "On Click property" of the button
public void myClickHandler(View view) { switch (view.getId()) { case R.id.Button01:
RadioButton celsiusButton = (RadioButton) findViewById(R.id.RadioButton01);
RadioButton fahrenheitButton = (RadioButton) findViewById(R.id.RadioButton02);
if (text.getText().length() == 0) { Toast.makeText(
this,
"Please enter a valid number", Toast.LENGTH_LONG).show();
return;
}
float inputValue = Float.parseFloat(text.getText().toString());
if (celsiusButton.isChecked()) { text.setText(String
.valueOf(convertFahrenheitToCelcius(inputValue)));
} else { text.setText(String
.valueOf(convertCelciusToFahrenheit(inputValue)));
}
// Switch to the other button
if (fahrenheitButton.isChecked()) { fahrenheitButton.setChecked(false);
celsiusButton.setChecked(true);
} else { fahrenheitButton.setChecked(true);
celsiusButton.setChecked(false);
}
break;
}
}
// Converts to celcius
private float convertFahrenheitToCelcius(float fahrenheit) { return ((fahrenheit - 32) * 5 / 9);
}
// Converts to fahrenheit
private float convertCelciusToFahrenheit(float celsius) { return ((celsius * 9) / 5) + 32;
}
}
Step6: You have done with generating all artifacts. Now you want to run your application and see the output. To run the application right click on TemperatureConverter –>Run as-> Android application
Emulator starts slowly…you’ll see the following output.
Our application appears in the main menu of the Android phone with android icon.

Readmore»»