0% found this document useful (0 votes)
2K views5 pages

Practical No 15

This document contains code for two Android practical examples. The first creates a layout with text and a button, then uses a button click handler to display a toast notification. The second creates a layout with checkboxes for items like pizza and coffee, and a button to display an order summary and total when checked items are selected. Both examples demonstrate basic user interface elements and responding to user interactions like button clicks.

Uploaded by

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

Practical No 15

This document contains code for two Android practical examples. The first creates a layout with text and a button, then uses a button click handler to display a toast notification. The second creates a layout with checkboxes for items like pizza and coffee, and a button to display an order summary and total when checked items are selected. Both examples demonstrate basic user interface elements and responding to user interactions like button clicks.

Uploaded by

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

Practical No 15

Q.1}
XML File:-
<?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"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World.Toast Example"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="show Toast"
android:onClick="Popup"/>
</LinearLayout>
Java:-
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Popup(View view)
{
Toast.makeText(this,"Message for you\nYou have got
mail!",Toast.LENGTH_LONG).show();
}
}
Output:-
Q.2}
XML File:-
<?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"
tools:context=".MainActivity"
android:orientation="vertical">

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pizza"
android:id="@+id/p"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coffe"
android:id="@+id/c"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Burger"
android:id="@+id/b"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="order"
android:onClick="order"/>
</LinearLayout>
Java:-
package com.example.a15_2;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


CheckBox pi,co,bu;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pi = (CheckBox) findViewById(R.id.p);
co = (CheckBox) findViewById(R.id.c);
bu = (CheckBox) findViewById(R.id.b);
}
public void order(View view)
{
StringBuilder res = new StringBuilder();
int total =0;
if (pi.isChecked())
{
res = res.append("\nPizza 100Rs");
total = total + 100;
}
if (co.isChecked())
{
res = res.append("\nCoffee 50Rs");
total = total + 50;
}
if (bu.isChecked())
{
res = res.append("\nBurger 120Rs");
total = total + 120;
}
Toast.makeText(this, "Selected Items"+res+"\nTotal "+total+"Rs",
Toast.LENGTH_LONG).show();
}
}
Output:-

You might also like