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

Ex 15

The document contains an XML layout file and Java code file for an Android application that displays checkboxes for pizza, coffee, and burger and calculates the total price when an order button is clicked by displaying a toast notification.

Uploaded by

suyashkurunkar
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)
81 views4 pages

Ex 15

The document contains an XML layout file and Java code file for an Android application that displays checkboxes for pizza, coffee, and burger and calculates the total price when an order button is clicked by displaying a toast notification.

Uploaded by

suyashkurunkar
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/ 4

Ex15_1

Xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<CheckBox
android:id="@+id/cb1"
android:layout_width="232dp"
android:layout_height="56dp"
android:text="Pizza"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.469"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.236"/>
<CheckBox
android:id="@+id/cb2"
android:layout_width="232dp"
android:layout_height="56dp"
android:text="Coffee"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.469"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.37"/>
<CheckBox
android:id="@+id/cb3"
android:layout_width="232dp"
android:layout_height="56dp"
android:text="Burger"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.469"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.485"/>
<Button
android:id="@+id/bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ORDER"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.781"/>
</LinearLayout>

Java file:
package com.example.ex15_1;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final CheckBox cb1=(CheckBox)findViewById(R.id.cb1);
final CheckBox cb2=(CheckBox) findViewById(R.id.cb2);
final CheckBox cb3=(CheckBox)findViewById(R.id.cb3);
final Button bt=(Button)findViewById(R.id.bt);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int total=0;
StringBuilder result=new StringBuilder();
result.append("selected items:");
if(cb1.isChecked()){
result.append("Pizza 100Rs");
total+=100;
}
if (cb2.isChecked()){
result.append("Coffee 50Rs");
total+=50;
}
if (cb3.isChecked()){
result.append("Burger 120Rs");
total+=120;
}
result.append("Total:"+total+"Rs");

Toast.makeText(getApplicationContext(),result,Toast.LENGTH_SHORT).sh
ow();
}
});
}
}

Output:-
Ex15_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"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World, Toast Example" />

<Button
android:id="@+id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast" />

</LinearLayout>

Java file:
package com.example.ex15_2;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button bt =(Button) findViewById(R.id.b);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Message for
you:" + "You have got mail!", Toast.LENGTH_SHORT).show();
}
});
}
}
Output:

You might also like