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

Check Box

The document contains an XML layout file for an Android application with three CheckBox elements labeled 'mumbai', 'pune', and 'sangola', along with a Button to display the checked items. The accompanying Java code defines a MainActivity that initializes the CheckBoxes and Button, and shows a Toast message listing the selected CheckBox texts when the Button is clicked. This structure allows users to select multiple options and receive feedback on their selections.

Uploaded by

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

Check Box

The document contains an XML layout file for an Android application with three CheckBox elements labeled 'mumbai', 'pune', and 'sangola', along with a Button to display the checked items. The accompanying Java code defines a MainActivity that initializes the CheckBoxes and Button, and shows a Toast message listing the selected CheckBox texts when the Button is clicked. This structure allows users to select multiple options and receive feedback on their selections.

Uploaded by

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

CheckBox-------------------------------------------------------

***********avtivity_main.xml*****************

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


<RelativeLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center">

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ch1"
android:text="mumbai"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ch2"
android:text="pune"
android:layout_below="@+id/ch1"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ch3"
android:text="sangola"
android:layout_below="@+id/ch2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:text="checked"
android:layout_below="@+id/ch3"
/>

</RelativeLayout>

*************main_activity.java***************
package com.example.abc;

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 {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);

CheckBox c1=(CheckBox) findViewById(R.id.ch1);


CheckBox c2=(CheckBox) findViewById(R.id.ch2);
CheckBox c3=(CheckBox) findViewById(R.id.ch3);
Button b=(Button) findViewById(R.id.b1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String status=" ";
if(c1.isChecked())
{
status=status+" "+c1.getText();
}
if(c2.isChecked())
{
status=status+" "+c2.getText();
}
if(c3.isChecked())
{
status=status+" "+c3.getText();
}

Toast.makeText(getApplicationContext(),status,Toast.LENGTH_LONG).show();
status=" ";
}
});

}
}

You might also like