0% found this document useful (0 votes)
13 views4 pages

Mad Prac9

The document contains two Android application programs: one for a toggle button to display ON/OFF status of Bluetooth, and another for a simple calculator. The Bluetooth toggle button utilizes a ToggleButton and displays a Toast message indicating the Bluetooth status. The calculator program allows users to perform addition, subtraction, multiplication, and division using two input numbers and displays the result on the screen.

Uploaded by

Vedant Nagul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Mad Prac9

The document contains two Android application programs: one for a toggle button to display ON/OFF status of Bluetooth, and another for a simple calculator. The Bluetooth toggle button utilizes a ToggleButton and displays a Toast message indicating the Bluetooth status. The calculator program allows users to perform addition, subtraction, multiplication, and division using two input numbers and displays the result on the screen.

Uploaded by

Vedant Nagul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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

activity_main.xml MainActivity.java
<?xml version="1.0" encoding="utf-8"?> package com.example.exp9_1;
<RelativeLayout import android.os.Bundle;
xmlns:android="http://schemas.android.com/apk/res/android" import android.app.*;
xmlns:app="http://schemas.android.com/apk/res-auto" import android.widget.Toast;
xmlns:tools="http://schemas.android.com/tools" import android.widget.ToggleButton;
android:id="@+id/main" import android.view.*;
android:layout_width="match_parent" public class MainActivity extends Activity {
android:layout_height="match_parent" ToggleButton tobu;
tools:context=".MainActivity"> @Override
<TextView protected void onCreate(Bundle
android:layout_width="wrap_content" savedInstanceState) {
android:layout_height="wrap_content" super.onCreate(savedInstanceState);
android:text="Bluetooth " setContentView(R.layout.activity_main);
android:textSize="25sp" tobu=findViewById(R.id.bt);
android:layout_above="@id/bt" }
android:layout_centerHorizontal="true" public void toggle(View v)
android:textStyle="italic|bold"/> {
<ToggleButton if(tobu.isChecked())
android:id="@+id/bt" Toast.makeText(this,"Bluetooth is On
android:layout_width="wrap_content" ",Toast.LENGTH_SHORT).show();
android:layout_height="wrap_content" else
android:layout_centerInParent="true" Toast.makeText(this,"Bluetooth is
android:textOff="Off" Off",Toast.LENGTH_SHORT).show();
android:textOn="On" }
android:background="#3944bc" }
android:textSize="20sp"
android:textColor="#ffffff"
android:onClick="toggle"/>
</RelativeLayout>
Q.2 Write a program to create a simple calculator.
activity_main.xml MainActivity.java
<?xml version="1.0" encoding="utf-8"?> package com.example.exp9_2;
<TableLayout import android.os.Bundle;
xmlns:android="http://schemas.android.com/apk/res/android" import android.view.View;
xmlns:app="http://schemas.android.com/apk/res-auto" import android.widget.EditText;
xmlns:tools="http://schemas.android.com/tools" import android.widget.TextView;
android:id="@+id/main"
android:layout_width="match_parent" import
android:layout_height="match_parent" androidx.appcompat.app.AppCompatActivity;
tools:context=".MainActivity"
android:layout_marginTop="40dp" public class MainActivity extends
android:layout_marginLeft="15dp" AppCompatActivity {
android:layout_marginRight="15dp"> EditText etnum1,etnum2;
<TextView TextView tvres;
android:layout_width="wrap_content" @Override
android:text="Simple calculator" protected void onCreate(Bundle
android:textSize="50sp" savedInstanceState) {
android:gravity="center" super.onCreate(savedInstanceState);
android:textStyle="bold|italic" setContentView(R.layout.activity_main);
android:layout_height="wrap_content"/> etnum1=findViewById(R.id.enum1);
<TableRow etnum2=findViewById(R.id.enum2);
android:weightSum="2"> tvres=findViewById(R.id.res);
<TextView }
android:layout_weight="1" public void Add(View v)
android:layout_width="wrap_content" {
android:layout_height="wrap_content" int
android:text="Enter Num 1" n1=Integer.parseInt(etnum1.getText().toString());
android:textSize="18sp"/> int
<EditText n2=Integer.parseInt(etnum2.getText().toString());
android:layout_weight="1" tvres.setText("Addition is :"+(n1+n2));
android:layout_height="50dp" }
android:layout_width="100dp" public void Sub(View v)
android:id="@+id/enum1" {
android:textSize="18sp" int
android:inputType="numberSigned"/> n1=Integer.parseInt(etnum1.getText().toString());
</TableRow> int
<TableRow n2=Integer.parseInt(etnum2.getText().toString());
android:weightSum="2"> tvres.setText("Substracttion is :"+(n1-n2));
<TextView }
android:layout_weight="1" public void Multi(View v)
android:layout_width="wrap_content" {
android:layout_height="wrap_content" int
android:text="Enter Num 2" n1=Integer.parseInt(etnum1.getText().toString());
android:textSize="18sp"/> int
<EditText n2=Integer.parseInt(etnum2.getText().toString());
android:layout_weight="1" tvres.setText("Multiplication is :"+(n1*n2));
android:layout_height="50dp" }
android:layout_width="100dp" public void Div(View v)
android:id="@+id/enum2" {
android:textSize="18sp" int
android:inputType="numberSigned"/> n1=Integer.parseInt(etnum1.getText().toString());
</TableRow> int
<TableRow n2=Integer.parseInt(etnum2.getText().toString());
android:weightSum="4" tvres.setText("Divition is :"+(n1/n2));
android:layout_marginTop="10dp"> }
<Button }
android:text="Add"
android:onClick="Add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:text="Sub"
android:onClick="Sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:text="Multi"
android:onClick="Multi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:text="Div"
android:onClick="Div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_marginTop="10dp">
<TextView
android:id="@+id/res"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20sp"/>
</TableRow>
</TableLayout>
Exp9_1. Output Exp9_2. Output

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy