Exp 5
Exp 5
COMPUTERSCIENCE&ENGI
NEERING
EXPERIMENT–5
STUDENT NAME:
Sidharth Kumar UID: 20BCS1997
BRANCH: BE-CSE SECTION/GROUP: 20BCS-DM-602/B
SEMESTER: 6TH SUBJECT CODE: 20CSP356
SUBJECT NAME: MAD LAB DATE: 06-03-2023
AIM/OVERVIEWOFTHEPRACTICAL:-
OBJECTIVE:-
STEPS:
1. CreateaNewProject
2. Click on the new project then empty activity and specify the android version and
language.
3. After the project has been created then write the code for creating the textbox to
show the message.
4. Write code for the main activity and the xml file.
5. Selectyourdeviceandrunthecode.
6. You can either run on virtual device or a physical device as according to your
preference.
DEPARTMENTOF
COMPUTERSCIENCE&ENGI
NEERING
CODE:-
XML:
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Choose your hobbies:"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/checkBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Painting"
android:layout_marginTop="16dp"
android:textSize="18sp" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Reading"
android:layout_marginTop="16dp"
android:textSize="18sp" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Singing"
android:textSize="18sp"
DEPARTMENTOF
COMPUTERSCIENCE&ENGI
NEERING
app:layout_constraintTop_toTopOf="@+id/textView"
tools:layout_editor_absoluteX="382dp" />
<CheckBox
android:id="@+id/checkBox4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cooking"
android:layout_marginTop="16dp"
android:textSize="18sp"
app:layout_constraintTop_toBottomOf="@+id/checkBox"
tools:layout_editor_absoluteX="386dp" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="Check"
android:text="submit" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
MAINACTIVITY.JAVA
package com.example.exp5;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(ch.isChecked())
msg = msg + " Painting ";
if(ch1.isChecked())
msg = msg + " Reading ";
if(ch2.isChecked())
msg = msg + " Singing ";
if(ch3.isChecked())
msg = msg + " Cooking ";
CODE:
MAINACTIVITY.JAVA
package com.example.exp5;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
public void onClick(View v) {
RadioButtonradioButton
= (RadioButton) radioGroup
.findViewById(selectedId);
@Override
public void onClick(View v) {
// Clear RadioGroup
// i.e. reset all the Radio Buttons
radioGroup.clearCheck();
}
});
}
}
ACTIVITY_MAIN.XML
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select your Subject ?"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:textSize="20sp"/>
<RadioGroup
android:layout_marginTop="50dp"
android:id="@+id/groupradio"
android:layout_marginLeft="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/radia_id1"
android:text="DBMS"
android:textSize="20sp"/>
DEPARTMENTOF
COMPUTERSCIENCE&ENGI
NEERING
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/radia_id2"
android:text="C/C++ Programming"
android:textSize="20sp"/>
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/radia_id3"
android:text="Data Structure"
android:textSize="20sp"/>
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/radia_id4"
android:text="Algorithms"
android:textSize="20sp"/>
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/submit"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="200dp"
android:layout_marginLeft="180dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
android:id="@+id/clear"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginTop="200dp"
android:layout_marginLeft="20dp"
/>
</RelativeLayout>
DEPARTMENTOF
COMPUTERSCIENCE&ENGI
NEERING
OUTPUT: