Android
Android
Android
Code name
API Level
1.5
Cupcake
1.6
Donut
2.1
Eclair
2.2
Froyo
2.3
Gingerbread
9 and 10
Honeycomb
12 and 13
4.0
15
Jelly Bean
16, 17 and 18
4.4
KitKat
19
5.0
Lollipop
21
6.0
Marshmallow
23
TASK-10
write a simple Android Application which will print "Hello World! Using Eclipse".
Requirements:
JDK 1.6 Or Above
ANDROID SDK
ECLIPSE IDE
To Download Android SDK using following Link
https://developer.android.com/sdk/index.html
The first step is to create a simple Android Application using Eclipse IDE. Follow the option File
-> New -> Project
and finally select Android New Application wizard from the wizard list. Now name your
application as HelloWorld
using the wizard window as follows:
Next, follow the
instructions provided and keep all other entries as default till the final step. Once your project is
created successfully,
you will have following project screen:
Android Application(View)
Before you run your app, you should be aware of a few directories and files in the Android
project:
S.N.
1.
3
4
5
6
}
}
The activity_main.xml is a layout file available in res/layout directory, that is referenced by
your application when
building its interface. You will modify this file very frequently to change the layout of your
application. For your "Hello
World!" application, this file will have following content related to default layout:
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextViewandroid:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="hello world"
tools:context=".MainActivity" />
</RelativeLayout>
Run on the Emulator
Whether you're using Eclipse or the command line, to run your app on the emulator you need to
first create an Android Virtual Device (AVD). An AVD is a device configuration for the Android
emulator that allows you to model different devices.
To create an AVD:
1. Launch the Android Virtual Device Manager:
In Eclipse, click Android Virtual Device Manager
2. In the Run as window that appears, select Android Application and click OK.
TASK -10
Write an Android application program that accepts a name from the user and
displays the hello name to the user in response as output using Eclipse.
FrmActivity.java
(Activity JAVA Prog)
package com.example1.myapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class FrmActivity extends Activity {
Button mButton;
EditText mEdit;
TextView mText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frm);
mButton = (Button)findViewById(R.id.button1);
mButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
mEdit = (EditText)findViewById(R.id.editText1);
mText = (TextView)findViewById(R.id.textView1);
mText.setText("Welcome "+mEdit.getText().toString()+"!");
}
});
}
}
activity_frm.xml (main.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".FrmActivity" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginLeft="18dp"
android:layout_marginTop="28dp"
android:text="@string/empty"
android:textColor="@color/Green"
android:textSize="32sp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="102dp"
android:text="@string/Input"
android:textColor="@color/BLUE"
android:textColorHint="@color/BLUE"
android:textSize="24sp" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/textView2"
android:layout_centerHorizontal="true"
android:background="#CCCCCC"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/editText1"
android:layout_below="@+id/textView2"
android:layout_marginRight="16dp"
android:layout_marginTop="17dp"
android:text="@string/sub"
android:textColor="@color/Green" />
</RelativeLayout>
Strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MyApp</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="empty">" "</string>
<string name="sub">Submit</string>
<string name="Input">Enter_name</string>
<color name="BLUE">#2372AC</color>
<color name="Green">#00ff00</color>
</resources>