You are on page 1of 6

Check Box Application

Dr. Sandip Mal


<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
XML Code
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
<CheckBox
tools:context="com.example.admin.sandip.checkbox.MainActivity"
android:id="@+id/checkBox3"
tools:showIn="@layout/activity_main">
android:layout_width="83dp"
android:layout_height="wrap_content"
<CheckBox
android:layout_marginBottom="326dp"
android:id="@+id/checkBox"
android:layout_marginEnd="237dp"
android:layout_width="wrap_content"
android:layout_marginStart="53dp"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:layout_marginBottom="430dp"
android:text="option 3"
android:layout_marginEnd="251dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginStart="48dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="49dp"
app:layout_constraintHorizontal_bias="0.0"
android:text="Option 1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintVertical_bias="1.0" />
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
<Button
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/button"
app:layout_constraintVertical_bias="0.0" />
android:layout_width="wrap_content"
<CheckBox
android:layout_height="wrap_content"
android:id="@+id/checkBox2"
android:layout_marginBottom="248dp"
android:layout_width="wrap_content"
android:layout_marginEnd="234dp"
android:layout_height="wrap_content"
android:layout_marginStart="62dp"
android:layout_marginBottom="375dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="242dp"
android:text="Submit"
android:layout_marginStart="48dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="23dp"
app:layout_constraintEnd_toEndOf="parent"
android:text="Option 2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox3" />
app:layout_constraintEnd_toEndOf="parent"
</android.support.constraint.ConstraintLayout>
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox"
app:layout_constraintVertical_bias="0.0" />
Edit Java File
1. Declare Variables
– private CheckBox c1,c2,c3;
private Button b;
2. Define a Function
public void addListerOnButton(){
c1=(CheckBox)findViewById(R.id.checkBox);
c2=(CheckBox)findViewById(R.id.checkBox2);
c3=(CheckBox)findViewById(R.id.checkBox3);
b=(Button)findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuffer s=new StringBuffer();
s.append("option 1").append(c1.isChecked());
s.append("option 2").append(c2.isChecked());
s.append("option 3").append(c3.isChecked());
Toast.makeText(MainActivity.this,s.toString(),Toast.LENGTH_LONG).show();
}
});
}
3. Call the function from onCreate() method.
Lab Assignment

Create three checkbox with three movie name. write


a program to display “--- movie is selected” if user
select single option. If user select multiple option
give message “You selected multiple option”

You might also like