<?xml version="1.0" encoding="utf-8"?
>
<AbsoluteLayout 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"
tools:context=".MainActivity">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="167dp"
android:layout_y="124dp"
android:text="Pizza"
tools:layout_editor_absoluteX="144dp"
tools:layout_editor_absoluteY="75dp" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="164dp"
android:layout_y="206dp"
android:text="Coffee"
tools:layout_editor_absoluteX="145dp"
tools:layout_editor_absoluteY="216dp" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="166dp"
android:layout_y="312dp"
android:text="Burger"
tools:layout_editor_absoluteX="144dp"
tools:layout_editor_absoluteY="25dp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="158dp"
android:layout_y="433dp"
android:text="Order"
tools:layout_editor_absoluteX="144dp"
tools:layout_editor_absoluteY="185dp" />
</AbsoluteLayout>
package com.example.prac15;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
CheckBox pizza,coffee,burger;
Button buttonorder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButtonClick();
}
public void addListenerOnButtonClick(){
pizza=findViewById(R.id.checkBox);
coffee=findViewById(R.id.checkBox2);
burger=findViewById(R.id.checkBox3);
buttonorder=findViewById(R.id.button);
buttonorder.setOnClickListener(view -> {
int totalamount = 0;
StringBuilder result = new StringBuilder();
result.append("Selected Items: ");
if (pizza.isChecked()){
result.append("\n checkBox 100Rs.");
totalamount+=100;
}
if (coffee.isChecked()) {
result.append("\n checkBox2 50Rs.");
totalamount += 50;
}
if (burger.isChecked()) {
result.append("\n checkBox3 120Rs.");
totalamount += 120;
}
result.append("\n Total:").append(totalamount).append("Rs");
Toast.makeText(getApplicationContext(),result.toString(),Toast.LENGTH_LONG).show();
});
}
}