0% found this document useful (0 votes)
12 views8 pages

17 Removed Merged

The document contains multiple XML layout files and corresponding Java activity files for Android applications. It includes a layout with an ImageButton that triggers a Toast message when clicked, as well as a layout with CheckBoxes for food items and a Button to display the selected items and total price. The Java activity files implement the lifecycle methods and handle user interactions with the UI elements.

Uploaded by

Kolekar Yashraj
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)
12 views8 pages

17 Removed Merged

The document contains multiple XML layout files and corresponding Java activity files for Android applications. It includes a layout with an ImageButton that triggers a Toast message when clicked, as well as a layout with CheckBoxes for food items and a Button to display the selected items and total price. The Java activity files implement the lifecycle methods and handle user interactions with the UI elements.

Uploaded by

Kolekar Yashraj
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/ 8

XML File Log.

d(TAG, "onStart: Activity is starting");


}
<?xml version="1.0" encoding="utf-8"?>
@Override
<LinearLayout
protected void onResume() {
xmlns:android="http://schemas.android.com/apk/
super.onResume();
res/android"
Log.d(TAG, "onResume: Activity is now visible
android:layout_width="match_parent"
and interactive");
android:layout_height="match_parent"
}
android:orientation="vertical"
@Override
android:gravity="center">
protected void onPause() {
<TextView
super.onPause();
android:layout_width="wrap_content"
Log.d(TAG, "onPause: Activity is partially
android:layout_height="wrap_content"
obscured (another activity is taking focus)");
android:text="Hello, World!"
}
android:textSize="24sp"
@Override
android:textStyle="bold"/>
protected void onStop() {
</LinearLayout>
super.onStop();
ACTIVITY File Log.d(TAG, "onStop: Activity is no longer
visible");
package com.technifysoft.prac17; }
@Override
import android.os.Bundle; protected void onRestart() {
super.onRestart();
import androidx.activity.EdgeToEdge; Log.d(TAG, "onRestart: Activity is restarting
import after being stopped");
androidx.appcompat.app.AppCompatActivity; }
import androidx.core.graphics.Insets; @Override
import androidx.core.view.ViewCompat; protected void onDestroy() {
import androidx.core.view.WindowInsetsCompat; super.onDestroy();
Log.d(TAG, "onDestroy: Activity is being
import android.os.Bundle; destroyed");
import android.util.Log; }
import }
androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends
AppCompatActivity {
private static final String TAG = ""
+".....Lifecycle";
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate: Activity is created");
}
@Override
protected void onStart() {
super.onStart();
OUTPUT
XML File

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<ImageButton
android:id="@+id/imageButton"
android:layout_width="60dp"
android:layout_height="60dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="@drawable/plant"
android:background="?attr/selectableItemBackgroundBorderless"
android:onClick="imageButtonClick"
android:contentDescription="Click Me" />

</LinearLayout>

ACTIVITY File Toast.makeText(this, "Image Button


Clicked!", Toast.LENGTH_SHORT).show();
package com.example.imagebutton;
}
import android.os.Bundle;
}
import android.view.View;

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);

public void imageButtonClick(View view) {


OUTPUT
app:layout_constraintTop_toBottomOf="@id/ch
XML File
kBurger"
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintL
app:layout_constraintStart_toStartOf="parent"
ayout
/>
xmlns:android="http://schemas.android.com/a

pk/res/android"
<CheckBox

android:id="@+id/chkPasta"
xmlns:app="http://schemas.android.com/apk/
android:layout_width="wrap_content"
res-auto"
android:layout_height="wrap_content"

android:text="Pasta - ₹80"
xmlns:tools="http://schemas.android.com/tool
android:textSize="18sp"
s"
android:padding="10dp"
android:layout_width="match_parent"

android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="@id/ch
tools:context=".MainActivity"
kPizza"
android:padding="20dp">

app:layout_constraintStart_toStartOf="parent"
<CheckBox
/>
android:id="@+id/chkBurger"

android:layout_width="wrap_content"
<Button
android:layout_height="wrap_content"
android:id="@+id/btnOrder"
android:text="Burger - ₹50"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Order"
app:layout_constraintTop_toTopOf="parent"
android:textSize="20sp"

android:padding="10dp"
app:layout_constraintStart_toStartOf="parent"

/>
app:layout_constraintTop_toBottomOf="@id/ch

kPasta"
<CheckBox

android:id="@+id/chkPizza"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="wrap_content"
/>
android:layout_height="wrap_content"

android:text="Pizza - ₹100"
</androidx.constraintlayout.widget.Constraint
android:textSize="18sp"
Layout>
android:padding="10dp"
ACTIVITY File OUTPUT

package com.technifysoft.pract15;

import android.os.Bundle; import


android.view.View; import
android.widget.Button; import
android.widget.CheckBox; import
android.widget.Toast; import
androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends
AppCompatActivity { CheckBox chkBurger,
chkPizza, chkPasta; Button btnOrder;
@Override protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //
Initialize checkboxes and button chkBurger =
findViewById(R.id.chkBurger); chkPizza =
findViewById(R.id.chkPizza); chkPasta =
findViewById(R.id.chkPasta); btnOrder =
findViewById(R.id.btnOrder); // Set button
click listener btnOrder.setOnClickListener(new
View.OnClickListener() { @Override public
void onClick(View v) { int totalPrice = 0;
StringBuilder orderSummary = new
StringBuilder("Selected Items:\n"); if
(chkBurger.isChecked()) {
orderSummary.append(" Burger - ₹50\n");
totalPrice += 50; } if (chkPizza.isChecked()) {
orderSummary.append(" Pizza - ₹100\n");
totalPrice += 100; } if (chkPasta.isChecked()) {
orderSummary.append(" Pasta - ₹80\n");
totalPrice += 80; } if (totalPrice == 0) {
orderSummary = new StringBuilder("No items
selected!"); } else {
orderSummary.append("\nTotal Price:
₹").append(totalPrice); } // Display the order
summary in a Toast
Toast.makeText(MainActivity.this,
orderSummary.toString(),
Toast.LENGTH_LONG).show(); } }); } }

You might also like