0% found this document useful (0 votes)
6 views5 pages

Worksheet 1.5 MAD

Uploaded by

Prakash Kumar
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)
6 views5 pages

Worksheet 1.5 MAD

Uploaded by

Prakash Kumar
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/ 5

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 5

Student Name: HIMANSHU UID: 20BET1033


Branch: IT Section/Group:
Subject Name: MAD LAB Subject Code: 20ITP-356

Aim: Create Checkbox and Display Selection in toast

Code for Login Function:


protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

// Finding CheckBox by its unique ID ch=(CheckBox)findViewById(R.id.checkBox);


ch1=(CheckBox)findViewById(R.id.checkBox2);
ch2=(CheckBox)findViewById(R.id.checkBox3);
ch3=(CheckBox)findViewById(R.id.checkBox4);

// This function is invoked when the button is pressed. public void


Check(View v) {
String msg="";

// Concatenation of the checked options in if


// isChecked() is used to check whether // the
CheckBox is in true state or not.

if(ch.isChecked())
msg = msg + " Painting ";
if(ch1.isChecked()) msg =
msg + " Reading ";
if(ch2.isChecked()) msg =
msg + " Singing ";
if(ch3.isChecked()) msg =
msg + " Cooking ";

// Toast is created to display the //


message using show() method.
Toast.makeText(this, msg + "are selected",
Toast.LENGTH_LONG).show();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Steps:

1. Open Android Studio and select your Template and Activity

2. Name your project and select your language and minimum SDK
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

3. You will get this interface

4. You can start building your application by just dragging and dropping the checkboxes
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
5. Now, go to each checkbox and give it a unique Id and a text corresponding to it.

6. Then edit your MainActivity.java in that you have to get the id of checkbox and then edit the code to
check if the checkbox is checked using the if else statements. Don’t forget to add this Check function to
your button (onClick).

7. Then run your app on the emulator to test it out.


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

8. Check the boxes and selected its will be displayed in the toast at the bottom of the screen.

You might also like