Professional Documents
Culture Documents
130160107069
Practical - 6
Aim: Create an Application for temperature convertor.
RelativeLayout
Properties
Value
layout_width
layout_height
paddingBottom
paddingLeft
paddingRight
paddingTop
tools:context
match_parent
match_parent
activity_vertical_margin
activity_horizontal_margin
activity_ horizontal _margin
activity_vertical_margin
com.rajan.prac6temperatureconverter.MainActi
vity
EditText
Properties
Value
id
layout_width
layout_height
layout_centerHorizontal
layout_marginTop
layout_marginLeft
editInput
match_parent
wrap_content
True
30dp
70dp
inputType
textSize
numberDecimal
16sp
RadioGroup
Properties
Value
id
layout_width
layout_height
layout_centerHorizontal
layout_marginTop
layout_below
Radiogrp
wrap_content
wrap_content
True
30dp
editInput
RadioButton
Properties
Value
id
layout_width
layout_height
text
textSize
checked
radbtnC
wrap_content
wrap_content
To Celcius
16sp
True
RadioButton
Properties
Value
id
layout_width
radbtnF
wrap_content
Page | 17
wrap_content
To Fahrenhiet
16sp
Button
Properties
Value
id
layout_width
layout_height
text
layout_centerHorizontal
layout_marginTop
layout_below
onClick
btnconvert
wrap_content
wrap_content
Convert
true
35dp
radiogrp
convert
TextView
Properties
Value
id
layout_width
layout_height
layout_centerHorizontal
layout_below
layout_marginTop
textSize
txtAns
wrap_content
wrap_content
true
btnconvert
58dp
24sp
[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.rajan.prac6temperatureconverter.MainActivity"
>
<EditText
android:id="@+id/editInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:layout_marginLeft="70dp"
android:inputType="numberDecimal"
Page | 18
android:textSize="16sp" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editInput"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:id="@+id/radiogrp">
<RadioButton
android:id="@+id/radbtnC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To Celcius"
android:textSize="16sp"
android:checked="true"/>
<RadioButton
android:id="@+id/radbtnF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To Fahrenhiet"
android:textSize="16sp"/>
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convert"
android:id="@+id/btnconvert"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:layout_below="@id/radiogrp"
android:onClick="convert"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtAns"
android:layout_below="@+id/btnconvert"
android:layout_centerHorizontal="true"
android:layout_marginTop="58dp"
android:textSize="24sp"/>
</RelativeLayout>
[MainActivity.java]
package com.manthan.prac6temperatureconverter;
Page | 19
import
import
import
import
android.support.v7.app.AppCompatActivity;
android.os.Bundle;
android.view.View;
android.widget.*;
!",
=
if (radbtnF.isChecked()) {
double ans = c2f(input);
txtAns.setText("Fahrenheit = " + ans);
}
}
}
private double c2f(double c) {
private double f2c(double f) {
return (c * 9) / 5 + 32; }
return (f - 32) * 5 / 9; }
Page | 20
Page | 21
Practical - 7
Aim: Create simple calculator.
RelativeLayout
Properties
Value
layout_width
layout_height
paddingBottom
paddingLeft
paddingRight
paddingTop
tools:context
match_parent
match_parent
activity_vertical_margin
activity_horizontal_margin
activity_ horizontal _margin
activity_vertical_margin
com.rajan.p7calculator.MainAc
tivity
EditText
Properties
Value
id
layout_width
layout_height
layout_marginTop
display
match_parent
wrap_content
24dp
textSize
enabled
textColor
32sp
false
black
Value
layout_width
layout_height
layout_below
wrap_content
wrap_content
display
layout_centerHorizontal
layout_marginTop
orientation
true
24dp
Vertical/Horizontal
Button
Properties
Value
id
layout_width
layout_height
Button[no]
70dp
wrap_content
text
textSize
[no]
28dp
[activity_main.xml]
<?xml version="1.0" encoding="utf-8"?>
Page | 22
<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.rajan.p7calculator.MainActivity">
<EditText
android:id="@+id/display"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:textSize="32sp"
android:enabled="false"
android:textColor="@android:color/black"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/display"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/button1"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="1"
android:textSize="28dp"/>
<Button
android:id="@+id/button2"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="2"
android:textSize="28dp"/>
<Button
android:id="@+id/button3"
android:layout_width="70dp"
Page | 23
android:layout_height="wrap_content"
android:text="3"
android:textSize="28dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="4"
android:textSize="28dp"/>
<Button
android:id="@+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="5"
android:textSize="28dp"/>
<Button
android:id="@+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="6"
android:textSize="28dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="7"
android:textSize="28dp"/>
<Button
android:id="@+id/button8"
style="?android:attr/buttonStyleSmall"
Page | 24
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="8"
android:textSize="28dp"/>
<Button
android:id="@+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="9"
android:textSize="28dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/button10"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="."
android:textSize="28dp"/>
<Button
android:id="@+id/button0"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="0"
android:textSize="28dp"/>
<Button
android:id="@+id/buttonC"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="C"
android:textSize="28dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/buttonEql"
android:layout_width="match_parent"
Page | 25
android:layout_height="wrap_content"
android:text="="
android:textSize="28dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@id/linearlayout1"
android:layout_marginLeft="24dp">
<Button
android:id="@+id/buttonAdd"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="+"
android:textSize="28dp"/>
<Button
android:id="@+id/buttonSub"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="-"
android:textSize="28dp"/>
<Button
android:id="@+id/buttonMul"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="*"
android:textSize="28dp"/>
<Button
android:id="@+id/buttonDiv"
style="?android:attr/buttonStyleSmall"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="/"
android:textSize="28dp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
[MainActivity.java]
package com.manthan.p7calculator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Page | 26
v)
button2.setOnClickListener(new View.OnClickListener() {
@Override
public
void
onClick(View
{
display.setText(display.getText() + "2");
}
});
v)
button3.setOnClickListener(new View.OnClickListener() {
@Override
public
void
onClick(View
{
display.setText(display.getText() + "3");
}
});
v)
button4.setOnClickListener(new View.OnClickListener() {
@Override
Page | 27
{
});
public
void
display.setText(display.getText() + "4");
onClick(View
}
v)
button5.setOnClickListener(new View.OnClickListener() {
@Override
public
void
onClick(View
{
display.setText(display.getText() + "5");
}
});
v)
button6.setOnClickListener(new View.OnClickListener() {
@Override
public
void
onClick(View
{
display.setText(display.getText() + "6");
}
});
v)
button7.setOnClickListener(new View.OnClickListener() {
@Override
public
void
onClick(View
{
display.setText(display.getText() + "7");
}
});
v)
button8.setOnClickListener(new View.OnClickListener() {
@Override
public
void
onClick(View
{
display.setText(display.getText() + "8");
}
});
v)
button9.setOnClickListener(new View.OnClickListener() {
@Override
public
void
onClick(View
{
display.setText(display.getText() + "9");
}
});
v)
button0.setOnClickListener(new View.OnClickListener() {
@Override
public
void
onClick(View
{
display.setText(display.getText() + "0");
}
});
v)
buttonAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (display == null) {
display.setText("");
} else {
mValueOne = Float.parseFloat(display.getText() + "");
mAddition = true;
display.setText(null);
}
}
});
buttonSub.setOnClickListener(new View.OnClickListener() {
Page | 28
display.setText(mValueOne +
display.setText(mValueOne -
display.setText(mValueOne *
display.setText(mValueOne /
buttonC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.setText("");
}
});
Page | 29
button10.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.setText(display.getText()
+ ".");
}
});
}
}
Page | 30
Practical - 8
Aim: Develop an android app which displays a form to
get following information from user.
i. Username
ii. Password iii. Email Address
iv. Phone Number v. Country
vi. State
vii. State
viii. Gender
ix. Interests
x.
Birth Date
Form should be followed by a Button with label
Submit. When user clicks the button, a message
should be displayed to user describing the
information entered. Use suitable UI controls (i.e.
widgets).
[When
user
enters
country
in
AutoCompleteTextView, list of states should be
displayed in Spinner automatically.]
RelativeLayout
Properties
Value
layout_width
layout_height
paddingBottom
paddingLeft
paddingRight
paddingTop
tools:context
match_parent
match_parent
activity_vertical_margin
activity_horizontal_margin
activity_ horizontal _margin
activity_vertical_margin
com.rajan.p8informationgatherfor
m.MainActivity
TextView
Properties
Value
id
layout_width
layout_height
layout_alignParentLeft
layout_alignParentStart
layout_alignParentTop
text
textSize
textView
wrap_content
wrap_content
true
true
true
Information Form
24sp
View
Properties
Value
layout_width
layout_height
layout_below
background
Match_parent
3dp
textView
darker_gray
Page | 31
EditText
Properties
Value
id
layout_width
layout_height
layout_marginLeft
layout_marginRight
layout_marginTop
hint
editText
wrap_content
wrap_content
8dp
8dp
16dp
Username
EditText
Properties
Value
id
layout_width
layout_height
layout_below
layout_marginLeft
layout_marginRight
hint
inputType
editText2
wrap_content
wrap_content
editText
8dp
8dp
Password
textPassword
EditText
Properties
Value
id
layout_width
layout_height
layout_below
layout_marginLeft
layout_marginRight
hint
inputType
editText3
wrap_content
wrap_content
editText2
8dp
8dp
E-Mail
textEmailAddress
EditText
Properties
Value
id
layout_width
layout_height
layout_below
layout_marginLeft
layout_marginRight
hint
inputType
editText4
wrap_content
wrap_content
editText3
8dp
8dp
Phone Number
numberDecimal
AutoCompleteTextView
Properties
Value
id
layout_width
layout_height
autoCompleteTextView
wrap_content
wrap_content
Page | 32
editText4
8dp
8dp
Country
Spinner
Properties
Value
id
layout_width
layout_height
layout_marginLeft
layout_marginRight
spinnerMode
spinner
fill_parent
wrap_content
8dp
8dp
dropdown
TextView
Properties
Value
id
layout_width
layout_height
layout_below
layout_marginLeft
layout_marginTop
text
textSize
gender
fill_parent
wrap_content
spinner
13dp
6dp
Gender :
16dp
RadioGroup
Properties
Value
id
layout_width
layout_height
layout_below
layout_marginLeft
layout_marginRight
layout_toRightOf
orientation
radioGroup
match_parent
wrap_content
spinner
8dp
8dp
gender
horizontal
RadioButton
Properties
Value
id
layout_width
layout_height
layout_weight
text
radioButton
0dp
wrap_content
1
Male
RadioButton
Properties
Value
id
layout_width
radioButton2
0dp
Page | 33
wrap_content
3
Female
EditText
Properties
Value
id
layout_width
layout_height
layout_below
layout_marginLeft
layout_marginRight
hint
inputType
editText5
match_parent
wrap_content
radioGroup
8dp
8dp
Birth Date
date
EditText
Properties
Value
id
layout_width
layout_height
layout_below
layout_marginLeft
hint
layout_alignRight
layout_alignEnd
editText6
match_parent
wrap_content
editText5
8dp
Interests
radioGroup
radioGroup
Button
Properties
Value
id
layout_width
layout_height
layout_below
layout_centerHorizontal
layout_marginTop
text
onClick
button
wrap_content
wrap_content
editText6
true
12dp
Submit
onClick
[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.rajan.p9informationgatherform.MainActivity">
Page | 34
<TextView
android:id="@+id/gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/spinner"
android:layout_marginLeft="13dp"
android:layout_marginTop="6dp"
android:text="Gender :"
android:textSize="16dp" />
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/spinner"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_toRightOf="@id/gender"
android:orientation="horizontal">
<RadioButton
android:id="@+id/radioButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Male" />
<RadioButton
Page | 36
[MainActivity.java]
package com.manthan.p9informationgatherform;
import
import
import
import
import
import
import
import
android.support.v7.app.AppCompatActivity;
android.os.Bundle;
android.text.Editable;
android.text.TextWatcher;
android.view.View;
android.widget.AdapterView;
android.widget.ArrayAdapter;
android.widget.AutoCompleteTextView;
Page | 37
new
textView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int
position, long id) {
spinner.setAdapter(adapterSpinner);
}
});
}
private static final String[] COUNTRIES = new String[] {
"India", "France", "Italy", "Germany", "Spain"
};
private static final String[] STATES = new String[] {
"Gujarat", "Rajasthan", "Madhya Pradesh", "Maharashtra", "Punjab"
};
public void onClick(View view){
Toast.makeText(this,
Toast.LENGTH_LONG).show();
}
"Information
Entered
Successfully",
[spinner_item.xml]
TextView
Properties
Value
layout_width
layout_height
textSize
match_parent
wrap_content
16sp
Page | 38
center
10dp
Page | 39
Page | 40
Practical - 9
Aim: Creating an Application with Multiple Activities and
a Simple Menu of five cities. When user select city it
will display city information in new activity.
[activity_main.xml]
RelativeLayout
Properties
Value
layout_width
layout_height
paddingBottom
paddingLeft
paddingRight
paddingTop
tools:context
match_parent
match_parent
activity_vertical_margin
activity_horizontal_margin
activity_ horizontal _margin
activity_vertical_margin
com.rajan.prac9multiactivity.Mai
nActivity
TextView
Properties
Value
id
layout_width
layout_height
layout_alignParentTop
layout_centerHorizontal
layout_marginTop
layout_marginLeft
text
textSize
textView
wrap_content
wrap_content
true
true
40dp
40dp
Select City Below
24sp
Spinner
Properties
Value
id
layout_width
layout_height
layout_centerHorizontal
layout_below
layout_marginLeft
layout_marginTop
spinnerCity
match_parent
wrap_content
true
textView
40dp
80dp
Button
Properties
Value
id
layout_width
layout_height
layout_centerHorizontal
layout_below
layout_marginTop
button
wrap_content
wrap_content
true
spinnerCity
80dp
Page | 41
Go
goToNewActivity
[MainActivity.java]
package com.manthan.prac9multiactivity;
import
import
import
import
import
import
import
import
import
android.content.Intent;
android.support.v7.app.AppCompatActivity;
android.os.Bundle;
android.view.MotionEvent;
android.view.View;
android.widget.AdapterView;
android.widget.ArrayAdapter;
android.widget.Spinner;
android.widget.Toast;
Page | 43
RelativeLayout
Properties
Value
layout_width
layout_height
paddingBottom
paddingLeft
paddingRight
paddingTop
tools:context
match_parent
match_parent
activity_vertical_margin
activity_horizontal_margin
activity_ horizontal _margin
activity_vertical_margin
com.rajan.prac9multiactivity.c
ity
TextView
Properties
Value
id
layout_width
layout_height
layout_alignParentLeft
layout_alignParentTop
layout_marginTop
text
txtCityName
wrap_content
wrap_content
true
true
40dp
Large Text
TextView
Properties
Value
id
layout_width
layout_height
layout_alignParentLeft
layout_alignParentStart
layout_below
layout_marginTop
text
textSize
layout_gravity
txtCityData
wrap_content
wrap_content
true
true
txtCityName
25dp
Small Text
16sp
center_vertical|right
Button
Properties
Value
id
layout_width
layout_height
layout_centerHorizontal
layout_marginTop
layout_alignParentBottom
layout_marginBottom
text
btnClose
wrap_content
wrap_content
true
50dp
true
40dp
Close Me !
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.rajan.prac9multiactivity.city">
<TextView
android:id="@+id/txtCityName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:text="Large Text"
<TextView
android:id="@+id/txtCityData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/txtCityName"
android:layout_marginTop="25dp"
android:text="Small Text"
android:textSize="16sp"
android:layout_gravity="center_vertical|right"/>
<Button
android:id="@+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="40dp"
android:text="Close Me !" />
</RelativeLayout>
[city.java]
package com.manthan.prac9multiactivity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
Page | 46
import
import
import
import
android.view.View;
android.webkit.WebView;
android.widget.Button;
android.widget.TextView;
[spinner_item.xml]
TextView
Properties
Value
layout_width
layout_height
textSize
gravity
padding
match_parent
wrap_content
24sp
center
15dp
Page | 47
Page | 48
Page | 49