ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
PRACTICAL-2
A. Create “hello world” application. That will display “Hello World” in the middle of the
screen in the black color with wheat color or white background.
B. create hello world using java
HelloMainActivity.java
package com.example.raj.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Activity_hello_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="#fafad2"
tools:context="com.example.raj.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Hello World"
android:textSize="30sp"
android:textColor="#B22222"
android:layout_centerVertical="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
android:layout_marginTop="99dp" />
</RelativeLayout>
Output:
B. Create hello world using java
package com.example.raj.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView text = new TextView(this);
text.setText("Hello World");
setContentView(text);
}
}
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
Output:
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
PRACTICAL-3
Create an Android App Which Has one Activity to get two numbers N1 and N2.on pressing
Button has four operation Add, Multiply, Divide, Subtract ,on select any one operation it
will Display Result in Text View of Activity
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#fafad2"
tools:context="com.example.raj.myapplication.MainActivity"
android:weightSum="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="No 1:"
android:id="@+id/tv1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etno1"
android:ems="10"
android:hint="Enter No1"
android:inputType="number"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="No 2:"
android:id="@+id/tv2" />
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etno2"
android:ems="10"
android:hint="Enter No2"
android:inputType="number"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Result is"
android:id="@+id/tv3"
android:layout_gravity="center" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="+"
android:id="@+id/Add" />
<Button
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="-"
android:id="@+id/Sub" />
<Button
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="*"
android:id="@+id/Mul" />
<Button
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="/"
android:id="@+id/Div" />
</LinearLayout>
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
</LinearLayout>
</LinearLayout>
MainActivity.java
package com.example.raj.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView tv1, tv2, Result;
EditText et1, et2;
Button Add, Sub, Mul, Div;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1 = (EditText)findViewById(R.id.etno1);
et2 = (EditText)findViewById(R.id.etno2);
Result = (TextView)findViewById(R.id.tv3);
Add = (Button)findViewById(R.id.Add);
Sub = (Button)findViewById(R.id.Sub);
Mul = (Button)findViewById(R.id.Mul);
Div = (Button)findViewById(R.id.Div);
Add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO Auto-Generated Method...
if(et1.getText().toString().equals(""))
{
et1.setError("Please fill the No1");
}
else if(et2.getText().toString().equals(""))
{
et2.setError("Please fill the No2");
}
else
{
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
int a = Integer.parseInt(et1.getText().toString());
int b = Integer.parseInt(et2.getText().toString());
int c = a + b;
Result.setText("Answer="+c);
}
}
});
Sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO Auto-Generated Method...
if(et1.getText().toString().equals(""))
{
et1.setError("Please fill the No1");
}
else if(et2.getText().toString().equals(""))
{
et2.setError("Please fill the No2");
}
else
{
int a = Integer.parseInt(et1.getText().toString());
int b = Integer.parseInt(et2.getText().toString());
int c = a - b;
Result.setText("Answer="+c);
}
}
});
Mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO Auto-Generated Method...
if(et1.getText().toString().equals(""))
{
et1.setError("Please fill the No1");
}
else if(et2.getText().toString().equals(""))
{
et2.setError("Please fill the No2");
}
else
{
int a = Integer.parseInt(et1.getText().toString());
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
int b = Integer.parseInt(et2.getText().toString());
int c = a * b;
Result.setText("Answer="+c);
}
}
});
Div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO Auto-Generated Method...
if(et1.getText().toString().equals(""))
{
et1.setError("Please fill the No1");
}
else if(et2.getText().toString().equals(""))
{
et2.setError("Please fill the No2");
}
else
{
int a = Integer.parseInt(et1.getText().toString());
int b = Integer.parseInt(et2.getText().toString());
int c = a / b;
Result.setText("Answer="+c);
}
}
});
}
}
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
OUTPUT:
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
PRACTICAL-4
Create application for demonstration of android activity life cycle.
Activity_life_cycle.xml
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.raj.lifecycle.LifeCycle">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Android Activity Life Cycle"
android:id="@+id/tv1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
LifeCycle.java
package com.example.raj.lifecycle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class LifeCycle extends AppCompatActivity {
TextView tv1;
String text;
@Override
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_life_cycle);
tv1 = (TextView)findViewById(R.id.tv1);
text = tv1.getText().toString();
text = text + "n InsideCreate Method";
tv1.setText(text);
}
public void onStart()
{
super.onStart();
text = tv1.getText().toString();
text = text + "n InsideStart Method";
tv1.setText(text);
}
public void onRestart()
{
super.onRestart();
text = tv1.getText().toString();
text = text + "n InsideRestart Method";
tv1.setText(text);
}
public void onResume()
{
super.onResume();
text = tv1.getText().toString();
text = text + "n InsideResume Method";
tv1.setText(text);
}
public void onPause()
{
super.onPause();
text = tv1.getText().toString();
text = text + "n InsidePause Method";
tv1.setText(text);
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
}
public void onStop()
{
super.onStop();
text = tv1.getText().toString();
text = text + "n InsideStop Method";
tv1.setText(text);
}
public void onDestroy()
{
super.onDestroy();
text = tv1.getText().toString();
text = text + "n InsideDestroy Method";
tv1.setText(text);
}
}
OUTPUT:
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
PRACTICAL-5
Create Registration page to demonstration of Basic widgets available in android.
Activity_widgetdemo.xml
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.raj.widgetdemo.widgetdemo">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Registration"
android:id="@+id/tv1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Name:"
android:id="@+id/tv2"
android:layout_below="@+id/tv1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="37dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Mobile No:"
android:id="@+id/tv3"
android:layout_below="@+id/tv2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
android:layout_marginTop="39dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et1"
android:layout_above="@+id/tv3"
android:layout_alignLeft="@+id/tv1"
android:layout_alignStart="@+id/tv1"
android:ems="10"
android:hint="name"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et2"
android:layout_alignTop="@+id/tv3"
android:layout_alignLeft="@+id/et1"
android:layout_alignStart="@+id/et1"
android:ems="10"
android:hint="mobile no"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Cast:"
android:id="@+id/tv4"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/et2"
android:layout_alignLeft="@+id/et2"
android:layout_alignStart="@+id/et2"
android:id="@+id/radioGroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="General"
android:id="@+id/rb1"
android:checked="false" />
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SEBC"
android:id="@+id/rb2"
android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SC"
android:id="@+id/rb3"
android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ST"
android:id="@+id/rb4"
android:checked="false" />
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Language:"
android:id="@+id/tv5"
android:layout_below="@+id/radioGroup"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="37dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gujarati"
android:id="@+id/chk1"
android:checked="false"
android:layout_alignBottom="@+id/tv5"
android:layout_alignLeft="@+id/btn"
android:layout_alignStart="@+id/btn" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hindi"
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
android:id="@+id/chk2"
android:checked="false"
android:layout_alignTop="@+id/chk1"
android:layout_toRightOf="@+id/tv1"
android:layout_toEndOf="@+id/tv1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUBMIT"
android:id="@+id/btn"
android:layout_alignLeft="@+id/radioGroup"
android:layout_alignStart="@+id/radioGroup"
android:layout_below="@+id/chk1"
android:onClick="submit"/>
</RelativeLayout>
widgetdemo.java
package com.example.raj.widgetdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class widgetdemo extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_widgetdemo);
}
public void submit(View v)
{
Toast.makeText(this,"You have Registered successfully.",Toast.LENGTH_LONG).show();
}
}
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
OUTPUT:
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
PRACTICAL-6
Create sample application with login module. (Check username and password) on
successful login, change Text view “Login Successful.” And on failing login, alert user using
Toast “Login fail.”
Activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.raj.loginpage.login"
android:background="#f0dfc9">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Login Page"
android:id="@+id/tv1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="37dp"
android:textColor="#116a1a"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="UserID:"
android:id="@+id/tv2"
android:layout_below="@+id/tv1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="55dp" />
<TextView
android:layout_width="wrap_content"
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Pass:"
android:id="@+id/tv3"
android:layout_below="@+id/tv2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="43dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et1"
android:ems="10"
android:hint="Enter User id"
android:layout_alignBottom="@+id/tv2"
android:layout_alignLeft="@+id/tv1"
android:layout_alignStart="@+id/tv1" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:hint="Enter Password"
android:numeric="integer"
android:id="@+id/et2"
android:layout_alignBottom="@+id/tv3"
android:layout_alignLeft="@+id/et1"
android:layout_alignStart="@+id/et1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/btn"
android:layout_below="@+id/et2"
android:layout_centerHorizontal="true"
android:layout_marginTop="37dp"
android:background="@android:color/darker_gray" />
</RelativeLayout>
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
login.java
package com.example.raj.loginpage;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class login extends AppCompatActivity {
EditText et1,et2;
Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
et1 = (EditText)findViewById(R.id.et1);
et2 = (EditText)findViewById(R.id.et2);
btn1 = (Button)findViewById(R.id.btn);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id = et1.getText().toString();
String pass = et2.getText().toString();
if(id.equals("abc")&& pass.equals("123"))
{
Toast.makeText(getApplicationContext(),"You have Login
Successfully",Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(),"Invalid ID and
Password",Toast.LENGTH_LONG).show();
}
}
});
}
}
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
OUTPUT:
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
PRACTICAL-7
Create an Android App which has one activity to get Fern hit or Celsius. On Pressing
“Convert” button it shows the Result will be displayed on Text View of Activity.
Activity_fernhit.xml
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.raj.fernhit.Fernhit">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et1"
android:ems="15"
android:hint="Enter Value"
android:layout_marginTop="52dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/tvResult"
android:text="Result"
android:layout_below="@+id/et1"
android:layout_alignLeft="@+id/et1"
android:layout_alignStart="@+id/et1" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Celcius"
android:id="@+id/cb"
android:layout_below="@+id/tvResult"
android:layout_alignLeft="@+id/tvResult"
android:layout_alignStart="@+id/tvResult"
android:layout_marginTop="45dp"
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fahrenhit"
android:id="@+id/fb"
android:checked="false"
android:layout_below="@+id/cb"
android:layout_alignLeft="@+id/cb"
android:layout_alignStart="@+id/cb" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convert"
android:id="@+id/btn1"
android:onClick="submit"
android:layout_below="@+id/fb"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Fernhit.java
package com.example.raj.fernhit;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
public class Fernhit extends AppCompatActivity {
EditText et1;
TextView tv1Result;
RadioButton cb,fb;
Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fernhit);
}
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
public void submit(View v)
{
et1 = (EditText)findViewById(R.id.et1);
tv1Result = (TextView)findViewById(R.id.tvResult);
double a = Double.parseDouble(String.valueOf(et1.getText()));
cb = (RadioButton)findViewById(R.id.cb);
fb = (RadioButton)findViewById(R.id.fb);
if(cb.isChecked())
{
tv1Result.setText(f2c(a)+"Degree C");
fb.setChecked(false);
}
else
{
tv1Result.setText(c2f(a)+"Degree F");
cb.setChecked(false);
}
}
private double c2f(double c)
{
return (c*9)/5+32;
}
private double f2c(double f)
{
return (f-32)*5/9;
}
}
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
OUTPUT:
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
PRACTICAL-8
Create application for demonstrate of second activity using intent.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.raj.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Show First Activity"
android:id="@+id/tv1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Second Activity"
android:id="@+id/btn1"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:onClick="Show"/>
</RelativeLayout>
MainActivity.java
package com.example.raj.myapplication;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Show(View v)
{
Intent i = new Intent(this,Main2Activity.class);
startActivity(i);
}
}
Activity_main2.xml
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.raj.myapplication.Main2Activity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Show Second Activity"
android:id="@+id/tv1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Main2Activity.java
package com.example.raj.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class Main2Activity extends AppCompatActivity {
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
}
OUTPUT:
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
PRACTICAL-9
Create application for demonstrate of data passing between First activity to second activity
using intent.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.raj.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Show First Activity"
android:id="@+id/tv1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et1"
android:hint="Enter Message"
android:layout_below="@+id/tv1"
android:layout_marginTop="64dp"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Second Activity"
android:id="@+id/btn1n"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:onClick="Show"/>
</RelativeLayout>
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
MainActivity.java
package com.example.raj.myapplication;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText et1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Show(View v)
{
et1 = (EditText)findViewById(R.id.et1);
String text = et1.getText().toString();
Intent i = new Intent(this, Main2Activity.class);
i.putExtra("text",text);
startActivity(i);
}
}
Activity_main2.xml
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.raj.myapplication.Main2Activity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Show Second Activity"
android:id="@+id/tv1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/tv2"
android:layout_below="@+id/tv1"
android:layout_alignLeft="@+id/tv1"
android:layout_marginTop="77dp" />
</RelativeLayout>
Main2Activity.java
package com.example.raj.myapplication;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class Main2Activity extends ActionBarActivity {
TextView tv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Intent i = getIntent();
String text = i.getStringExtra("text");
tv2 = (TextView)findViewById(R.id.tv2);
tv2.setText(text);
}
}
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
OUTPUT:
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
PRACTICAL-10
Create application for demonstrate of call Built-in application for (ACTION_VIEW &
ACTION_DIAL) activity using intent.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.raj.google.Google">
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/imageButton"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@mipmap/ic_launcher_google1"
android:onClick="Google"/>
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/imageButton2"
android:layout_alignTop="@+id/imageButton"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="@mipmap/ic_launcher_dial"
android:onClick="Dial"/>
</RelativeLayout>
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
MainActivity.java
package com.example.raj.google;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class Google extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google);
}
public void Google(View v)
{
Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
startActivity(i);
}
public void Dial(View v)
{
Intent i = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:+91"));
startActivity(i);
}
}
ANDROID APPLICATION
DEPARTMET OF COMPUTER ENGINEERING
OUTPUT:

Practical

  • 1.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING PRACTICAL-2 A. Create “hello world” application. That will display “Hello World” in the middle of the screen in the black color with wheat color or white background. B. create hello world using java HelloMainActivity.java package com.example.raj.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } Activity_hello_main.xml <?xml version="1.0" encoding="utf-8"?> <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" android:background="#fafad2" tools:context="com.example.raj.myapplication.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Hello World" android:textSize="30sp" android:textColor="#B22222" android:layout_centerVertical="true" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"
  • 2.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING android:layout_marginTop="99dp" /> </RelativeLayout> Output: B. Create hello world using java package com.example.raj.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView text = new TextView(this); text.setText("Hello World"); setContentView(text); } }
  • 3.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING Output:
  • 4.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING PRACTICAL-3 Create an Android App Which Has one Activity to get two numbers N1 and N2.on pressing Button has four operation Add, Multiply, Divide, Subtract ,on select any one operation it will Display Result in Text View of Activity Activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" android:background="#fafad2" tools:context="com.example.raj.myapplication.MainActivity" android:weightSum="1"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="No 1:" android:id="@+id/tv1" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/etno1" android:ems="10" android:hint="Enter No1" android:inputType="number"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="No 2:" android:id="@+id/tv2" />
  • 5.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/etno2" android:ems="10" android:hint="Enter No2" android:inputType="number"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Result is" android:id="@+id/tv3" android:layout_gravity="center" /> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center"> <Button android:layout_width="70dp" android:layout_height="wrap_content" android:text="+" android:id="@+id/Add" /> <Button android:layout_width="70dp" android:layout_height="wrap_content" android:text="-" android:id="@+id/Sub" /> <Button android:layout_width="70dp" android:layout_height="wrap_content" android:text="*" android:id="@+id/Mul" /> <Button android:layout_width="70dp" android:layout_height="wrap_content" android:text="/" android:id="@+id/Div" /> </LinearLayout>
  • 6.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING </LinearLayout> </LinearLayout> MainActivity.java package com.example.raj.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends AppCompatActivity { TextView tv1, tv2, Result; EditText et1, et2; Button Add, Sub, Mul, Div; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et1 = (EditText)findViewById(R.id.etno1); et2 = (EditText)findViewById(R.id.etno2); Result = (TextView)findViewById(R.id.tv3); Add = (Button)findViewById(R.id.Add); Sub = (Button)findViewById(R.id.Sub); Mul = (Button)findViewById(R.id.Mul); Div = (Button)findViewById(R.id.Div); Add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //TODO Auto-Generated Method... if(et1.getText().toString().equals("")) { et1.setError("Please fill the No1"); } else if(et2.getText().toString().equals("")) { et2.setError("Please fill the No2"); } else {
  • 7.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING int a = Integer.parseInt(et1.getText().toString()); int b = Integer.parseInt(et2.getText().toString()); int c = a + b; Result.setText("Answer="+c); } } }); Sub.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //TODO Auto-Generated Method... if(et1.getText().toString().equals("")) { et1.setError("Please fill the No1"); } else if(et2.getText().toString().equals("")) { et2.setError("Please fill the No2"); } else { int a = Integer.parseInt(et1.getText().toString()); int b = Integer.parseInt(et2.getText().toString()); int c = a - b; Result.setText("Answer="+c); } } }); Mul.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //TODO Auto-Generated Method... if(et1.getText().toString().equals("")) { et1.setError("Please fill the No1"); } else if(et2.getText().toString().equals("")) { et2.setError("Please fill the No2"); } else { int a = Integer.parseInt(et1.getText().toString());
  • 8.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING int b = Integer.parseInt(et2.getText().toString()); int c = a * b; Result.setText("Answer="+c); } } }); Div.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //TODO Auto-Generated Method... if(et1.getText().toString().equals("")) { et1.setError("Please fill the No1"); } else if(et2.getText().toString().equals("")) { et2.setError("Please fill the No2"); } else { int a = Integer.parseInt(et1.getText().toString()); int b = Integer.parseInt(et2.getText().toString()); int c = a / b; Result.setText("Answer="+c); } } }); } }
  • 9.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING OUTPUT:
  • 10.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING PRACTICAL-4 Create application for demonstration of android activity life cycle. Activity_life_cycle.xml <?xml version="1.0" encoding="utf-8"?> <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="com.example.raj.lifecycle.LifeCycle"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Android Activity Life Cycle" android:id="@+id/tv1" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> </RelativeLayout> LifeCycle.java package com.example.raj.lifecycle; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class LifeCycle extends AppCompatActivity { TextView tv1; String text; @Override
  • 11.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_life_cycle); tv1 = (TextView)findViewById(R.id.tv1); text = tv1.getText().toString(); text = text + "n InsideCreate Method"; tv1.setText(text); } public void onStart() { super.onStart(); text = tv1.getText().toString(); text = text + "n InsideStart Method"; tv1.setText(text); } public void onRestart() { super.onRestart(); text = tv1.getText().toString(); text = text + "n InsideRestart Method"; tv1.setText(text); } public void onResume() { super.onResume(); text = tv1.getText().toString(); text = text + "n InsideResume Method"; tv1.setText(text); } public void onPause() { super.onPause(); text = tv1.getText().toString(); text = text + "n InsidePause Method"; tv1.setText(text);
  • 12.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING } public void onStop() { super.onStop(); text = tv1.getText().toString(); text = text + "n InsideStop Method"; tv1.setText(text); } public void onDestroy() { super.onDestroy(); text = tv1.getText().toString(); text = text + "n InsideDestroy Method"; tv1.setText(text); } } OUTPUT:
  • 13.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING PRACTICAL-5 Create Registration page to demonstration of Basic widgets available in android. Activity_widgetdemo.xml <?xml version="1.0" encoding="utf-8"?> <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="com.example.raj.widgetdemo.widgetdemo"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Registration" android:id="@+id/tv1" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Name:" android:id="@+id/tv2" android:layout_below="@+id/tv1" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="37dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Mobile No:" android:id="@+id/tv3" android:layout_below="@+id/tv2" android:layout_alignParentLeft="true" android:layout_alignParentStart="true"
  • 14.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING android:layout_marginTop="39dp" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/et1" android:layout_above="@+id/tv3" android:layout_alignLeft="@+id/tv1" android:layout_alignStart="@+id/tv1" android:ems="10" android:hint="name"/> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/et2" android:layout_alignTop="@+id/tv3" android:layout_alignLeft="@+id/et1" android:layout_alignStart="@+id/et1" android:ems="10" android:hint="mobile no"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Cast:" android:id="@+id/tv4" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/et2" android:layout_alignLeft="@+id/et2" android:layout_alignStart="@+id/et2" android:id="@+id/radioGroup"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="General" android:id="@+id/rb1" android:checked="false" />
  • 15.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SEBC" android:id="@+id/rb2" android:checked="false" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SC" android:id="@+id/rb3" android:checked="false" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ST" android:id="@+id/rb4" android:checked="false" /> </RadioGroup> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Language:" android:id="@+id/tv5" android:layout_below="@+id/radioGroup" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="37dp" /> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Gujarati" android:id="@+id/chk1" android:checked="false" android:layout_alignBottom="@+id/tv5" android:layout_alignLeft="@+id/btn" android:layout_alignStart="@+id/btn" /> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hindi"
  • 16.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING android:id="@+id/chk2" android:checked="false" android:layout_alignTop="@+id/chk1" android:layout_toRightOf="@+id/tv1" android:layout_toEndOf="@+id/tv1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SUBMIT" android:id="@+id/btn" android:layout_alignLeft="@+id/radioGroup" android:layout_alignStart="@+id/radioGroup" android:layout_below="@+id/chk1" android:onClick="submit"/> </RelativeLayout> widgetdemo.java package com.example.raj.widgetdemo; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class widgetdemo extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_widgetdemo); } public void submit(View v) { Toast.makeText(this,"You have Registered successfully.",Toast.LENGTH_LONG).show(); } }
  • 17.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING OUTPUT:
  • 18.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING PRACTICAL-6 Create sample application with login module. (Check username and password) on successful login, change Text view “Login Successful.” And on failing login, alert user using Toast “Login fail.” Activity_login.xml <?xml version="1.0" encoding="utf-8"?> <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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.example.raj.loginpage.login" android:background="#f0dfc9"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Login Page" android:id="@+id/tv1" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="37dp" android:textColor="#116a1a" android:textStyle="bold" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="UserID:" android:id="@+id/tv2" android:layout_below="@+id/tv1" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="55dp" /> <TextView android:layout_width="wrap_content"
  • 19.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Pass:" android:id="@+id/tv3" android:layout_below="@+id/tv2" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="43dp" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/et1" android:ems="10" android:hint="Enter User id" android:layout_alignBottom="@+id/tv2" android:layout_alignLeft="@+id/tv1" android:layout_alignStart="@+id/tv1" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textPassword" android:ems="10" android:hint="Enter Password" android:numeric="integer" android:id="@+id/et2" android:layout_alignBottom="@+id/tv3" android:layout_alignLeft="@+id/et1" android:layout_alignStart="@+id/et1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Login" android:id="@+id/btn" android:layout_below="@+id/et2" android:layout_centerHorizontal="true" android:layout_marginTop="37dp" android:background="@android:color/darker_gray" /> </RelativeLayout>
  • 20.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING login.java package com.example.raj.loginpage; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class login extends AppCompatActivity { EditText et1,et2; Button btn1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); et1 = (EditText)findViewById(R.id.et1); et2 = (EditText)findViewById(R.id.et2); btn1 = (Button)findViewById(R.id.btn); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String id = et1.getText().toString(); String pass = et2.getText().toString(); if(id.equals("abc")&& pass.equals("123")) { Toast.makeText(getApplicationContext(),"You have Login Successfully",Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(),"Invalid ID and Password",Toast.LENGTH_LONG).show(); } } }); } }
  • 21.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING OUTPUT:
  • 22.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING PRACTICAL-7 Create an Android App which has one activity to get Fern hit or Celsius. On Pressing “Convert” button it shows the Result will be displayed on Text View of Activity. Activity_fernhit.xml <?xml version="1.0" encoding="utf-8"?> <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="com.example.raj.fernhit.Fernhit"> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/et1" android:ems="15" android:hint="Enter Value" android:layout_marginTop="52dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/tvResult" android:text="Result" android:layout_below="@+id/et1" android:layout_alignLeft="@+id/et1" android:layout_alignStart="@+id/et1" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Celcius" android:id="@+id/cb" android:layout_below="@+id/tvResult" android:layout_alignLeft="@+id/tvResult" android:layout_alignStart="@+id/tvResult" android:layout_marginTop="45dp"
  • 23.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING android:checked="false" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Fahrenhit" android:id="@+id/fb" android:checked="false" android:layout_below="@+id/cb" android:layout_alignLeft="@+id/cb" android:layout_alignStart="@+id/cb" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Convert" android:id="@+id/btn1" android:onClick="submit" android:layout_below="@+id/fb" android:layout_centerHorizontal="true" /> </RelativeLayout> Fernhit.java package com.example.raj.fernhit; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; import android.widget.TextView; public class Fernhit extends AppCompatActivity { EditText et1; TextView tv1Result; RadioButton cb,fb; Button btn1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fernhit); }
  • 24.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING public void submit(View v) { et1 = (EditText)findViewById(R.id.et1); tv1Result = (TextView)findViewById(R.id.tvResult); double a = Double.parseDouble(String.valueOf(et1.getText())); cb = (RadioButton)findViewById(R.id.cb); fb = (RadioButton)findViewById(R.id.fb); if(cb.isChecked()) { tv1Result.setText(f2c(a)+"Degree C"); fb.setChecked(false); } else { tv1Result.setText(c2f(a)+"Degree F"); cb.setChecked(false); } } private double c2f(double c) { return (c*9)/5+32; } private double f2c(double f) { return (f-32)*5/9; } }
  • 25.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING OUTPUT:
  • 26.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING PRACTICAL-8 Create application for demonstrate of second activity using intent. Activity_main.xml <?xml version="1.0" encoding="utf-8"?> <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="com.example.raj.myapplication.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Show First Activity" android:id="@+id/tv1" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show Second Activity" android:id="@+id/btn1" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:onClick="Show"/> </RelativeLayout> MainActivity.java package com.example.raj.myapplication; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompatActivity {
  • 27.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void Show(View v) { Intent i = new Intent(this,Main2Activity.class); startActivity(i); } } Activity_main2.xml <?xml version="1.0" encoding="utf-8"?> <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="com.example.raj.myapplication.Main2Activity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Show Second Activity" android:id="@+id/tv1" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> </RelativeLayout> Main2Activity.java package com.example.raj.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class Main2Activity extends AppCompatActivity {
  • 28.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); } } OUTPUT:
  • 29.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING PRACTICAL-9 Create application for demonstrate of data passing between First activity to second activity using intent. Activity_main.xml <?xml version="1.0" encoding="utf-8"?> <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="com.example.raj.myapplication.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Show First Activity" android:id="@+id/tv1" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/et1" android:hint="Enter Message" android:layout_below="@+id/tv1" android:layout_marginTop="64dp" android:layout_alignParentRight="true" android:layout_alignParentLeft="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show Second Activity" android:id="@+id/btn1n" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:onClick="Show"/> </RelativeLayout>
  • 30.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING MainActivity.java package com.example.raj.myapplication; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; public class MainActivity extends AppCompatActivity { EditText et1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void Show(View v) { et1 = (EditText)findViewById(R.id.et1); String text = et1.getText().toString(); Intent i = new Intent(this, Main2Activity.class); i.putExtra("text",text); startActivity(i); } } Activity_main2.xml <?xml version="1.0" encoding="utf-8"?> <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="com.example.raj.myapplication.Main2Activity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Show Second Activity" android:id="@+id/tv1" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" />
  • 31.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/tv2" android:layout_below="@+id/tv1" android:layout_alignLeft="@+id/tv1" android:layout_marginTop="77dp" /> </RelativeLayout> Main2Activity.java package com.example.raj.myapplication; import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; public class Main2Activity extends ActionBarActivity { TextView tv2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); Intent i = getIntent(); String text = i.getStringExtra("text"); tv2 = (TextView)findViewById(R.id.tv2); tv2.setText(text); } }
  • 32.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING OUTPUT:
  • 33.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING PRACTICAL-10 Create application for demonstrate of call Built-in application for (ACTION_VIEW & ACTION_DIAL) activity using intent. Activity_main.xml <?xml version="1.0" encoding="utf-8"?> <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="com.example.raj.google.Google"> <ImageButton android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/imageButton" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:background="@mipmap/ic_launcher_google1" android:onClick="Google"/> <ImageButton android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/imageButton2" android:layout_alignTop="@+id/imageButton" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:background="@mipmap/ic_launcher_dial" android:onClick="Dial"/> </RelativeLayout>
  • 34.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING MainActivity.java package com.example.raj.google; import android.content.Intent; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; public class Google extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_google); } public void Google(View v) { Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com")); startActivity(i); } public void Dial(View v) { Intent i = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:+91")); startActivity(i); } }
  • 35.
    ANDROID APPLICATION DEPARTMET OFCOMPUTER ENGINEERING OUTPUT: