0% found this document useful (0 votes)
8 views2 pages

Practical No 11

The document contains an XML layout for an Android application with a CheckBox, Button, and TextView. The MainActivity class manages user interactions, checking if the CheckBox is selected when the Button is clicked, and updates the TextView accordingly. It provides feedback on whether the user has agreed to the terms and conditions.

Uploaded by

Vaman Kulkarni
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)
8 views2 pages

Practical No 11

The document contains an XML layout for an Android application with a CheckBox, Button, and TextView. The MainActivity class manages user interactions, checking if the CheckBox is selected when the Button is clicked, and updates the TextView accordingly. It provides feedback on whether the user has agreed to the terms and conditions.

Uploaded by

Vaman Kulkarni
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/ 2

Practical No 11

<?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:orientation="vertical"
android:gravity="center"
android:padding="16dp">
<!-- CheckBox -->
<CheckBox
android:id="@+id/agreeCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/i_agree_to_terms_and_conditions"
android:layout_marginBottom="20dp"/>
<!-- Button -->
<Button
android:id="@+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/submit" />
<!-- TextView to display the result -->
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@android:color/black"
android:layout_marginTop="20dp"/>
</LinearLayout>

Main.java

package com.example.chechbox;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private CheckBox agreeCheckBox;


private TextView resultTextView;

@SuppressLint("SetTextI18n")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Initialize UI components
agreeCheckBox = findViewById(R.id.agreeCheckBox);
Button submitButton = findViewById(R.id.submitButton);
resultTextView = findViewById(R.id.resultTextView);

// Set the button click listener


submitButton.setOnClickListener(v -> {
// Check if the checkbox is checked
if (agreeCheckBox.isChecked()) {
resultTextView.setText("You have agreed to the terms and conditions.");
} else {
resultTextView.setText("You must agree to the terms and conditions.");
}
});
}
}

OUTPUT:

You might also like