You are on page 1of 33

Mobile Computing and Wireless Communication

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

Mobile Computing and Wireless Communication


130160107069
layout_height
text
textSize

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

Mobile Computing and Wireless Communication


130160107069

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

Mobile Computing and Wireless Communication


130160107069

import
import
import
import

android.support.v7.app.AppCompatActivity;
android.os.Bundle;
android.view.View;
android.widget.*;

public class MainActivity extends AppCompatActivity {


protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void convert(View v) {
EditText editInput = (EditText) findViewById(R.id.editInput);
TextView txtAns = (TextView) findViewById(R.id.txtAns);
RadioButton
radbtnC
=
(RadioButton)
findViewById(R.id.radbtnC);
RadioButton radbtnF = (RadioButton) findViewById(R.id.radbtnF);
if (editInput.getText().toString().equals("")) {
Toast.makeText(this, "Enter Something
Toast.LENGTH_SHORT).show();
} else {
double
input
Double.parseDouble(editInput.getText().toString());
if (radbtnC.isChecked()) {
double ans = f2c(input);
txtAns.setText("Celcius = " + ans);
}

!",
=

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

Mobile Computing and Wireless Communication


130160107069

Page | 21

Mobile Computing and Wireless Communication


130160107069

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

LinearLayout (for all)


Properties

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

Where [no] ranges from 0 to 10, C, Eql, Add(+), Sub(-),


Mul(*), Div (/)

[activity_main.xml]
<?xml version="1.0" encoding="utf-8"?>

Page | 22

Mobile Computing and Wireless Communication


130160107069

<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

Mobile Computing and Wireless Communication


130160107069

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

Mobile Computing and Wireless Communication


130160107069

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

Mobile Computing and Wireless Communication


130160107069

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

Mobile Computing and Wireless Communication


130160107069
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Button button0, button1, button2, button3, button4, button5, button6,
button7, button8, button9, buttonAdd, buttonSub, buttonDivision,
buttonMul, button10, buttonC, buttonEqual;
EditText display;
float mValueOne, mValueTwo;
boolean mAddition, mSubtract, mMultiplication, mDivision;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button0 = (Button) findViewById(R.id.button0);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
button5 = (Button) findViewById(R.id.button5);
button6 = (Button) findViewById(R.id.button6);
button7 = (Button) findViewById(R.id.button7);
button8 = (Button) findViewById(R.id.button8);
button9 = (Button) findViewById(R.id.button9);
button10 = (Button) findViewById(R.id.button10);
buttonAdd = (Button) findViewById(R.id.buttonAdd);
buttonSub = (Button) findViewById(R.id.buttonSub);
buttonMul = (Button) findViewById(R.id.buttonMul);
buttonDivision = (Button) findViewById(R.id.buttonDiv);
buttonC = (Button) findViewById(R.id.buttonC);
buttonEqual = (Button) findViewById(R.id.buttonEql);
display = (EditText) findViewById(R.id.display);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public
void
onClick(View
{
display.getText(display.getText() + "1");
}
});

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

Mobile Computing and Wireless Communication


130160107069

{
});

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

Mobile Computing and Wireless Communication


130160107069
@Override
public void onClick(View v) {
mValueOne = Float.parseFloat(display.getText() + "");
mSubtract = true;
display.setText(null);
}
});
buttonMul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne = Float.parseFloat(display.getText() + "");
mMultiplication = true;
display.setText(null);
}
});
buttonDivision.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne = Float.parseFloat(display.getText() + "");
mDivision = true;
display.setText(null);
}
});
buttonEqual.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueTwo = Float.parseFloat(display.getText() + "");
if (mAddition == true) {
mValueTwo + "");
mAddition = false;
}
if (mSubtract == true) {
mValueTwo + "");
mSubtract = false;
}
if (mMultiplication == true) {
mValueTwo + "");
mMultiplication = false;
}
if (mDivision == true) {
mValueTwo + "");
mDivision = false;
}
}
});

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

Mobile Computing and Wireless Communication


130160107069

button10.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.setText(display.getText()
+ ".");
}
});
}
}

Page | 30

Mobile Computing and Wireless Communication


130160107069

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

Mobile Computing and Wireless Communication


130160107069

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

Mobile Computing and Wireless Communication


130160107069
layout_below
layout_marginLeft
layout_marginRight
hint

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

Mobile Computing and Wireless Communication


130160107069
layout_height
layout_weight
text

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

Mobile Computing and Wireless Communication


130160107069
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="Information Form"
android:textSize="24sp" />
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="@+id/textView"
android:background="@android:color/darker_gray" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="16dp"
android:hint="Username" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:hint="Password"
android:inputType="textPassword" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:hint="E-Mail"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
Page | 35

Mobile Computing and Wireless Communication


130160107069
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:hint="Phone Number"
android:inputType="numberDecimal" />
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText4"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:hint="Country" />
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:spinnerMode="dropdown" />

<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

Mobile Computing and Wireless Communication


130160107069
android:id="@+id/radioButton2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Female" />
</RadioGroup>
<EditText
android:id="@+id/editText5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Birth Date"
android:inputType="date"
android:layout_below="@id/radioGroup"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"/>
<EditText
android:id="@+id/editText6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText5"
android:hint="Interests"
android:layout_marginLeft="8dp"
android:layout_alignRight="@+id/radioGroup"
android:layout_alignEnd="@+id/radioGroup" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText6"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:text="Submit"
android:onClick="onClick"/>
</RelativeLayout>

[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

Mobile Computing and Wireless Communication


130160107069
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//for AutoComplete
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
final AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.autoCompleteTextView);
textView.setAdapter(adapter);
final ArrayAdapter<String> adapterSpinner
ArrayAdapter<String>(this, R.layout.spinner_item, STATES);
final Spinner spinner = (Spinner)findViewById(R.id.spinner);

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

Mobile Computing and Wireless Communication


130160107069
gravity
padding

center
10dp

<?xml version="1.0" encoding="utf-8"?>


<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:gravity="center"
android:padding="10dp" />

Page | 39

Mobile Computing and Wireless Communication


130160107069

Page | 40

Mobile Computing and Wireless Communication


130160107069

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

Mobile Computing and Wireless Communication


130160107069
text
onClick

Go
goToNewActivity

<?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.prac9multiactivity.MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="Select City Below"
android:layout_marginLeft="40dp"
android:textSize="24sp" />
<Spinner
android:id="@+id/spinnerCity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/textView"
android:layout_marginLeft="40dp"
android:layout_marginTop="80dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go"
android:id="@+id/button"
android:layout_below="@+id/spinnerCity"
android:layout_marginTop="80dp"
android:layout_centerHorizontal="true"
android:onClick="goToNewActivity"/>
</RelativeLayout>
Page | 42

Mobile Computing and Wireless Communication


130160107069

[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;

public class MainActivity extends AppCompatActivity {


private static final String CITYS[] = new String[]{
"Himatnagar", "Ahmedabad", "Surat", "Vadodara", "Rajkot"
};
private static final String CITYSDATA[] = new String[]{
"Himatnagar was founded in 1426 by Ahmed Shah I of Gujarat
Sultanate and named it Ahmednagar after himself." +
" He founded the town to keep Raos of Idar State in
check. " +
"It is said that he was so fond of the place that he
thought of making it, instead of Ahmedabad, the capital of
Gujarat Sultanate." +
"When the Rao dynasty took Idar in 1728, Ahmednagar
soon fell into their hands. " +
"After the death of Maharaja Shivsing, in 1792, his
brother Sangramsing took Ahmednagar and the country round;
and, in spite of the efforts of his nephew Gambhirsing, became
an independent chief.",
"Ahmedabad also known as Amdavad is the largest city and
former capital of Gujarat, which is a state in India. " +
"It is the administrative headquarters of the Ahmedabad
district and the seat of the Gujarat High Court. " +
"With a population of more than 6.3 million and an
extended population of 7.8 million, it is the sixth largest city and
seventh largest metropolitan area of India. " +
"Ahmedabad is located on the banks of the Sabarmati
River, 30 km (19 mi) from the state capital Gandhinagar.",
"Surat, is a port city previously known as Suryapur, is a city
and former princely state in the Indian state of Gujarat." +
"It is the administrative capital of the Surat district. " +

Page | 43

Mobile Computing and Wireless Communication


130160107069

"The city is located 284 kilometres (176 mi) south of the


state capital, Gandhinagar; 265 kilometres (165 mi) south of
Ahmedabad; and 289 kilometres (180 mi) north of Mumbai.",
"Vadodara, which used to be known as Baroda, the Cultural
Capital of Gujarat, is the third largest city in the Western Indian
State of Gujarat, after Ahmedabad and Surat. " +
"It is the administrative headquarters of Vadodara
District and is located on the banks of the Vishwamitri river,
southeast of Ahmedabad, 139 kilometres (86 mi) from the state
capital Gandhinagar.",
"Rajkot is the fourth largest city in the state of Gujarat, India,
after Ahmedabad, Surat, and Vadodara." +
" Rajkot is the centre of the Saurashtra region of Gujarat.
"+
"Rajkot is the 35th-largest urban agglomeration in India,
with a population more than 1.2 million as of 2015." +
"Rajkot is the seventh[4][5] cleanest city of India. Rajkot
is also the 147th-fastest-growing city in the world." +
"The city contains the administrative headquarters of the
Rajkot District, 245 km from the state capital Gandhinagar, and is
located on the banks of the Aji and Nyari rivers."
};
String cityname, citydata;
Spinner spinnerCity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cityname = citydata = "";
spinnerCity = (Spinner) findViewById(R.id.spinnerCity);
final ArrayAdapter<String> adapterSpinner = new
ArrayAdapter<String>(this, R.layout.spinner_item, CITYS);
spinnerCity.setAdapter(adapterSpinner);
}
public void goToNewActivity(View v) {
cityname = spinnerCity.getSelectedItem().toString();
long pos = spinnerCity.getSelectedItemPosition();
citydata = CITYSDATA[(int)pos];
Intent i = new Intent(getApplicationContext(), city.class);
i.putExtra("cityname", cityname);
i.putExtra("citydata", citydata);
startActivity(i);
}
}
[activity_city.xml]
Page | 44

Mobile Computing and Wireless Communication


130160107069

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 !

<?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"
Page | 45

Mobile Computing and Wireless Communication


130160107069

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

Mobile Computing and Wireless Communication


130160107069

import
import
import
import

android.view.View;
android.webkit.WebView;
android.widget.Button;
android.widget.TextView;

public class city extends AppCompatActivity {


TextView txtCityName, txtCityData;
Button btnClose;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_city);
Intent i =getIntent();
String gotTextCityName = i.getStringExtra("cityname");
String gotTextCityData = i.getStringExtra("citydata");
txtCityName = (TextView) findViewById(R.id.txtCityName);
txtCityData = (TextView) findViewById(R.id.txtCityData);
txtCityName.setText("" + gotTextCityName);
txtCityData.setText("" + gotTextCityData);
btnClose = (Button) findViewById(R.id.btnClose);
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}

[spinner_item.xml]

TextView
Properties

Value

layout_width
layout_height
textSize
gravity
padding

match_parent
wrap_content
24sp
center
15dp
Page | 47

Mobile Computing and Wireless Communication


130160107069

<?xml version="1.0" encoding="utf-8"?>


<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:gravity="center"
android:padding="15dp" />

Page | 48

Mobile Computing and Wireless Communication


130160107069

Page | 49

You might also like