0% found this document useful (0 votes)
15 views6 pages

Practical 12

The document describes a mobile application development exercise that involves creating a program with five checkboxes and a button to display selected checkboxes using toast messages. It includes XML code for the layout and Java code for the functionality of the application. The application allows users to select hobbies and submit their choices, which are then displayed as a toast message.

Uploaded by

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

Practical 12

The document describes a mobile application development exercise that involves creating a program with five checkboxes and a button to display selected checkboxes using toast messages. It includes XML code for the layout and Java code for the functionality of the application. The application allows users to select hobbies and submit their choices, which are then displayed as a toast message.

Uploaded by

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

Subject :- Mobile Application Developmen Subject Code :- 22617

Name :- Shivam Sainath Korpakwad Batch :- CO 6 IA Roll No. 24

Exercise :-

1). Write a program to show five checkboxes and toast selected checkboxes.
Xml Code :
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<CheckBox
android:id="@+id/cb2"
android:layout_width="128dp”
android:layout_height="wrap_content"
android:layout_below="@+id/cb1"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:layout_x="125dp"
android:layout_y="185dp"
android:checked="true"
android:text="Dancing" />
<CheckBox
android:id="@+id/cb1"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/cb2"
android:layout_alignParentTop="true"
android:layout_marginTop="72dp"
android:layout_x="125dp"
android:layout_y="132dp"
android:text="Coding" />
<CheckBox
android:id="@+id/cb3"
android:layout_width="129dp"
android:layout_height="wrap_content"
android:layout_below="@+id/cb2"
android:layout_alignLeft="@+id/cb2"
android:layout_marginTop="18dp"
android:layout_x="125dp"
android:layout_y="236dp"
android:text="Traveling" />
<CheckBox
android:id="@+id/cb4"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:layout_below="@+id/cb2"
android:layout_alignLeft="@+id/cb2"
android:layout_marginLeft="0dp"
android:layout_marginTop="68dp"
android:layout_x="128dp"
android:layout_y="291dp"
android:text="Singing" />
<CheckBox
android:id="@+id/cb5"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:layout_below="@+id/cb2"
android:layout_alignLeft="@+id/cb2"
android:layout_marginLeft="0dp"
android:layout_marginTop="68dp"
android:layout_x="128dp"
android:layout_y="349dp"
android:text="Coocking" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_x="60dp"
android:layout_y="27dp"
android:text="Choose your hobbies"
android:textSize="30dp" />
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="141dp"
android:layout_y="447dp"
android:text="Submit" />
</AbsoluteLayout>
java Code :
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity
{
CheckBox c1,c2,c3,c4,c5;
Button b;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
c1= CheckBox)findViewById(R.id.cb1);
c2=(CheckBox)findViewById(R.id.cb2);
c3=(CheckBox)findViewById(R.id.cb3);
c3= CheckBox)findViewById(R.id.cb3);
c4= CheckBox)findViewById(R.id.cb4);
c5= CheckBox)findViewById(R.id.cb5);
b = (Button)findViewById(R.id.b1);
b.setOnClickListener(new view.OnClickListener()
{
@Override
public void onClick(View v)
{
StringBuffer result = new StringBuffer();
result.append("The selected checkbox is ");
if(c1.isChecked())
{
result.append(c1.getText());
}
if(c2.isChecked())
{
result.append(c2.getText());
}
if(c3.isChecked())
{
result.append(c3.getText());
}
if(c4.isChecked())
{
result.append(c4.getText());
}
if(c5.isChecked())
{
result.append(c5.getText());
}
Toast.makeText(MainActivity.this,result.toString(),Toast.LENGTH_LONG).show();
}
});
}
}
Output :-

You might also like