0% found this document useful (0 votes)
3 views

Practical 9

The document contains two exercises related to mobile application development. The first exercise involves creating a toggle button to control Bluetooth status, while the second exercise focuses on displaying user information (Name, Age, Mobile Number) centrally on the screen using an Absolute layout. Both exercises include XML layout code and Java code for functionality.

Uploaded by

sainathkorpakwad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Practical 9

The document contains two exercises related to mobile application development. The first exercise involves creating a toggle button to control Bluetooth status, while the second exercise focuses on displaying user information (Name, Age, Mobile Number) centrally on the screen using an Absolute layout. Both exercises include XML layout code and Java code for functionality.

Uploaded by

sainathkorpakwad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Subject :- Mobile Application Developmen Subject Code :- 22617

Name :- Shivam Sainath Korpakwad Batch :- CO 6 IA Roll No. 24

Exercise :-

1). Write a program to create a toggle button to display ON/OFF Bluetooth on the display
screen..

Code :-

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


<RelativeLayout
xmlns:android="http://schemas.android.com/
apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<Switch
android:id="@+id/switchBluetooth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Bluetooth"
android:textSize="18sp"
android:layout_marginTop="50dp"/>
<TextView
android:id="@+id/textViewBluetoothStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/switchBluetooth"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Bluetooth is OFF"
android:textSize="16sp"/>
<TextView
android:id="@+id/textViewExecutedBy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Executed by Shivam,
Roll No.24"
android:textSize="16sp"
android:textColor="#666666"
android:layout_below="@id/textViewBluetoothStatus"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"/>
</RelativeLayout>
Java Code:
package com.example.myapplication;
import
androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import
androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends
AppCompatActivity {
private Switch switchBluetooth;
private TextView textViewBluetoothStatus;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
witchBluetooth =
findViewById(R.id.switchBluetooth);
textViewBluetoothStatus = findViewById(R.id.textViewBluetoothStatus);
switchBluetooth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void
onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
// Bluetooth is ON
textViewBluetoothStatus.setText("Bluetooth is ON");
} else {
// Bluetooth is OFF
textViewBluetoothStatus.setText("Bluetooth is OFF");
}
}
});
}
}

Output :-
2). Write a program to place Name, Age and Mobile Number centrally on the display
screen using Absolute layout.

Code :-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/
apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TextView
android:id="@+id/textViewEquation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:layout_marginBottom="8dp"/>
<TextView
android:id="@+id/textViewResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0"
android:textSize="24sp"
android:textAlignment="textEnd"
android:layout_below="@id/textViewEquation"
android:layout_marginBottom="16dp"/>
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textViewResult"
android:layout_marginTop="16dp"
android:columnCount="4">
<!-- Row 1 -->
<Button
android:id="@+id/btn7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="7"/>
<Button
android:id="@+id/btn8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="8"/>
<Button
android:id="@+id/btn9"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="9"/>
<Button
android:id="@+id/btnDivide"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="/"/>
<!-- Row 2 -->
<Button
android:id="@+id/btn4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="4"/>
<Button
android:id="@+id/btn5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="5"/>
<Button
android:id="@+id/btn6"
android:layout_width="0dp”
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="6"/>
<Button
android:id="@+id/btnMultiply”
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="*"/>
<!-- Row 3 -->
<Button
android:id="@+id/btn1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="1"/>
<Button
android:id="@+id/btn2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="2"/>
<Button
android:id="@+id/btn3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="3"/>
<Button
android:id="@+id/btnSubtract"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="-"/>
<!-- Row 4 -->
<Button
android:id="@+id/btn0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill_horizontal"
android:text="0"/>
<Button
android:id="@+id/btnDot"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1”
android:text="."/>
<Button
android:id="@+id/btnEquals"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="="/>
<Button
android:id="@+id/btnAdd"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="+"/>
<Button
android:id="@+id/btnClear"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="C"/>
</GridLayout>
<TextView
android:id="@+id/textViewExecutedBy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Executed by Shivam, Roll No.24"
android:textSize="16sp"
android:textColor="#666666”
android:layout_centerHorizontal="true"
android:layout_marginTop="400dp"/>
</RelativeLayout>

Output :-

You might also like