Smt.
Chandaben Mohanbhai Patel Institute of Computer Applications
CA330 - Basics of Mobile Applications
Practical Assignment-2
Roll No:-23BCA317
1. Create calculator application with two EditText to enter numbers, 4 Buttons to perform
Addition, Subtraction, Division, Multiplication and display answer into toast. (Check for
blank value and 0 value input) (Use proper controls)
->Kotlin Code
package [Link].ass_q_1
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_main)
val name: EditText=findViewById([Link])
val name1: EditText=findViewById([Link].editTextText2)
val btn: Button=findViewById([Link])
val btn2: Button=findViewById([Link].button2)
val btn3: Button=findViewById([Link].button3)
val btn4: Button=findViewById([Link].button4)
val vn: TextView=findViewById([Link])
[Link] {
var no1=[Link]().toInt()
var no2=[Link]().toInt()
var ans=no1+no2
[Link]([Link]())
[Link](this,[Link](), Toast.LENGTH_SHORT).show()
}
[Link] {
var no1=[Link]().toInt()
var no2=[Link]().toInt()
var ans=no1-no2
[Link]([Link]())
[Link](this,ans, Toast.LENGTH_SHORT).show()
}
[Link] {
var no1=[Link]().toInt()
var no2=[Link]().toInt()
var ans=no1*no2
[Link]([Link]())
[Link](this,[Link](), Toast.LENGTH_SHORT).show()
}
[Link] {
var no1=[Link]().toInt()
var no2=[Link]().toInt()
if (no2==0){
[Link](this,"Can't Divided By Zero", Toast.LENGTH_SHORT).show()
}
else{
var ans=no1/no2
[Link]([Link]())
[Link](this,[Link](), Toast.LENGTH_SHORT).show()
}
}
[Link](findViewById([Link])) { v, insets ->
val systemBars = [Link]([Link]())
[Link]([Link], [Link], [Link], [Link])
insets
}
}
}
XML code->
<?xml version="1.0" encoding="utf-8"?>
<[Link] xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="240dp"
android:layout_height="0dp"
android:layout_marginStart="13dp"
android:layout_marginBottom="208dp"
android:textColor="#E91E63"
android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button3" />
<EditText
android:id="@+id/editTextText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="71dp"
android:layout_marginBottom="43dp"
android:ems="10"
android:gravity="center"
android:hint="Enter Number"
android:inputType="text"
app:layout_constraintBottom_toTopOf="@+id/editTextText2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editTextText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="58dp"
android:ems="10"
android:gravity="center"
android:hint="Enter Number"
android:inputType="text"
app:layout_constraintBottom_toTopOf="@+id/button3"
app:layout_constraintStart_toStartOf="@+id/editTextText"
app:layout_constraintTop_toBottomOf="@+id/editTextText" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="262dp"
android:layout_marginEnd="14dp"
android:layout_marginBottom="15dp"
android:text="+"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
app:layout_constraintBaseline_toBaselineOf="@+id/button3"
app:layout_constraintEnd_toStartOf="@+id/button3"
app:layout_constraintStart_toEndOf="@+id/button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="14dp"
android:layout_marginBottom="15dp"
android:text="*"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintEnd_toStartOf="@+id/button4"
app:layout_constraintStart_toEndOf="@+id/button2"
app:layout_constraintTop_toBottomOf="@+id/editTextText2" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:text="/"
app:layout_constraintBaseline_toBaselineOf="@+id/button3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/button3" />
</[Link]>
Output->
2. Write an android application that will take basic student information (Student ID, Student
Name, Student Branch, Student Contact No., Student Birth date) in one screen from user
and display that information to other screen on submit button click of first screen) (Use
proper controls)
Kotlin Code(Activity-1)->
package [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_main)
val eid: EditText=findViewById([Link])
val ename: EditText=findViewById([Link])
val ebranch: EditText=findViewById([Link])
val edob: EditText=findViewById([Link])
val eaddress: EditText=findViewById([Link])
val eno: EditText=findViewById([Link])
val btn: Button=findViewById([Link])
[Link] {
val name=[Link]().trim()
val branch=[Link]().trim()
val dob=[Link]().trim()
val address=[Link]().trim()
val no=[Link]().trim()
val id=[Link]().trim()
if ([Link]()||[Link]()||[Link]()||[Link]()||[Link]())
{
[Link](this,"Please Enter Reqiuerments...", Toast.LENGTH_SHORT).show()
}
else{
val intent= Intent(this, result::[Link])
[Link]("name",name)
[Link]("id",id)
[Link]("branch",branch)
[Link]("address",address)
[Link]("pno",no)
[Link]("dob",dob)
startActivity(intent)}
}
}
}
XML Code(Activity-1)->
<ScrollView xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText android:id="@+id/etName" android:hint="Name"
android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:id="@+id/etId" android:hint="Student ID"
android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:id="@+id/etBranch" android:hint="Branch"
android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:id="@+id/etDob" android:hint="DOB"
android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:id="@+id/etAddress" android:hint="Address"
android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:id="@+id/etPhone" android:hint="Phone"
android:inputType="phone"
android:layout_width="match_parent" android:layout_height="wrap_content"/>
<Button
android:id="@+id/btnSubmit"
android:text="Submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
OutPut(Activity-1)
Kotlin Code(Activity-2)
package [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class result : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_main2)
val tv1: TextView=findViewById([Link])
val tv2: TextView=findViewById([Link].textView2)
val tv3: TextView=findViewById([Link].textView3)
val tv4: TextView=findViewById([Link].textView4)
val tv5: TextView=findViewById([Link].textView5)
val tv6: TextView=findViewById([Link].textView6)
val id=[Link]("id")
val branch=[Link]("branch")
val name=[Link]("name")
val dob=[Link]("dob")
val address=[Link]("address")
val pno=[Link]("pno")
[Link]="ID:$id"
[Link]="Name:$name"
[Link]="Dob:$dob"
[Link]="Branch:$branch"
[Link]="Address:$address"
[Link]="Phone Number:$pno"
}
}
XML Code(Activity-2)
<LinearLayout xmlns:android="[Link]
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/tvResult"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="44dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="44dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="44dp" />
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="44dp" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="44dp" />
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="44dp" />
</LinearLayout>
OutPut(Activity-2)
3. Create an Android application that should have 2 screens: Login Screen, Home Screen.
When user start application for first time, Login screen should appear. User will login
with Username: “admin” and Password: “admin”. After successful login, user will
redirect to home screen. Where Welcome [Username] should be display. (Use explicit
Intent)
Kotlin Code(Activity-1)->
package [Link].ass_2_q_3
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_main)
val name: EditText=findViewById([Link])
val pass: EditText=findViewById([Link])
val btn: Button=findViewById([Link])
[Link] {
val uname=[Link]().trim()
val pas=[Link]().trim()
if ([Link]()||[Link]())
{
[Link](this,"Enter UserName&Password", Toast.LENGTH_SHORT).show()
}
else{
if (uname=="admin"&&pas=="1234")
{
[Link](this,"Login Success", Toast.LENGTH_SHORT).show()
val intent= Intent(this, HomeActivity::[Link])
[Link]("name",uname)
startActivity(intent)
}
else{
[Link](this,"Invalid Name & Password", Toast.LENGTH_SHORT).show()
}
}
}
[Link](findViewById([Link])) { v, insets ->
val systemBars = [Link]([Link]())
[Link]([Link], [Link], [Link], [Link])
insets
}
}
}
XML Code(Activity-1)->
<?xml version="1.0" encoding="utf-8"?>
<[Link] xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/etname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="111dp"
android:ems="10"
android:hint="Enter UserName"
android:inputType="text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextNumberPassword" />
<EditText
android:id="@+id/editTextNumberPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:ems="10"
android:inputType="numberPassword"
app:layout_constraintStart_toStartOf="@+id/etname"
app:layout_constraintTop_toBottomOf="@+id/etname" />
</[Link]>
OutPut(Activity-1)->
Kotlin Code(Activity-2)->
package [Link].ass_2_q_3
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class HomeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_home)
val tv: TextView=findViewById([Link])
val name=[Link]("name")
[Link]="WellCome $name"
[Link](findViewById([Link])) { v, insets ->
val systemBars = [Link]([Link]())
[Link]([Link], [Link], [Link], [Link])
insets
}
}
}
XML Code(Activity-2)
<?xml version="1.0" encoding="utf-8"?>
<[Link] xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeActivity">
<TextView
android:id="@+id/textView"
android:layout_width="222dp"
android:layout_height="48dp"
android:layout_marginStart="80dp"
android:layout_marginTop="114dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
OutPut(Activity-2)->
4. Open CHARUSAT website using Implicit Intent.
Kotlin Code->
package [Link].ass_2_q_4
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_main)
val btn: Button=findViewById([Link])
[Link] {
val intent= Intent(Intent.ACTION_VIEW, [Link]("[Link]
startActivity(intent)
}
[Link](findViewById([Link])) { v, insets ->
val systemBars = [Link]([Link]())
[Link]([Link], [Link], [Link], [Link])
insets
}
}
}
Xml Code->
<?xml version="1.0" encoding="utf-8"?>
<[Link] xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="136dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
OutPut->
5. Create Application of Alert Dialog Box contains following three components.
1. Title
2. Message
3. Buttons (that trigger Negative and Positive Actions)
Kotlin Code->
package [Link].ass_2_q_5
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_main)
val btn: Button=findViewById([Link])
[Link] {
val builder= [Link](this)
//Title
[Link]("AlertDialogExample")
//msg
[Link]("Do You Want To Close It ??")
[Link]([Link].baseline_add_alert_24)
//Positive Button
//[Link]("Yes"){ Dialog,which->finish() }
[Link]("Yes",{ DialogInterface,i:Int->finish()})
[Link]("No",{ DialogInterface,i:Int->[Link]()}).show()
}
[Link](findViewById([Link])) { v, insets ->
val systemBars = [Link]([Link]())
[Link]([Link], [Link], [Link], [Link])
insets
}
}
}
XmlCode->
<?xml version="1.0" encoding="utf-8"?>
<[Link] xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="62dp"
android:layout_marginEnd="83dp"
android:text="Close"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
OutPut->
6. Display Toast message by clicking on Image Button and open CHARUSAT website
using webview.
Kotlin Code->
package [Link].ass_2_q_6
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_main)
val imgbtn: ImageButton=findViewById([Link])
val wv: WebView=findViewById([Link])
[Link]= WebViewClient()
[Link] {
[Link](this,"Opening Charusat Website", Toast.LENGTH_SHORT).show()
[Link]("[Link]
}
[Link](findViewById([Link])) { v, insets ->
val systemBars = [Link]([Link]())
[Link]([Link], [Link], [Link], [Link])
insets
}
}
}
XmlCode->
<?xml version="1.0" encoding="utf-8"?>
<[Link] xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="88dp"
android:layout_height="78dp"
android:layout_marginStart="35dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="18dp"
android:foregroundGravity="center"
android:scaleType="centerInside"
app:layout_constraintBottom_toTopOf="@+id/web"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:src="@drawable/charusat_logo" />
<WebView
android:id="@+id/web"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageButton" />
</[Link]>
OutPut->
7. Write a program using Radiobutton and display message in Toast.
Kotlin Code->
package [Link].ass_2_q_7
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_main)
val rmale: RadioButton=findViewById([Link])
val rfmale: RadioButton=findViewById([Link])
val cbca: CheckBox=findViewById([Link])
val cmca: CheckBox=findViewById([Link])
val cbsc: CheckBox=findViewById([Link])
[Link] {
[Link](this,"Male Selected", Toast.LENGTH_SHORT).show()
}
[Link] {
[Link](this,"Female Selected", Toast.LENGTH_SHORT).show()
}
[Link] {
var msg = ""
if ([Link]) {
msg += "BCA "
}
if ([Link]) {
msg += "MCA "
}
if ([Link]) {
msg += "BSC(IT) "
}
if ([Link]()) {
[Link](this, msg + "Selected", Toast.LENGTH_SHORT).show()
}
}
[Link] {
var msg = ""
if ([Link]) {
msg += "BCA "
}
if ([Link]) {
msg += "MCA "
}
if ([Link]) {
msg += "BSC(IT) "
}
if ([Link]()) {
[Link](this, msg + "Selected", Toast.LENGTH_SHORT).show()
}
}
[Link] {
var msg = ""
if ([Link]) {
msg += "BCA "
}
if ([Link]) {
msg += "MCA "
}
if ([Link]) {
msg += "BSC(IT) "
}
if ([Link]()) {
[Link](this, msg + "Selected", Toast.LENGTH_SHORT).show()
}
}
[Link](findViewById([Link])) { v, insets ->
val systemBars = [Link]([Link]())
[Link]([Link], [Link], [Link], [Link])
insets
}
}
}
XML Code->
<LinearLayout
xmlns:android="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"/>
<RadioButton
android:id="@+id/radiofemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"/>
</RadioGroup>
<CheckBox
android:id="@+id/checkBoxBca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BCA"/>
<CheckBox
android:id="@+id/checkBoxMca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MCA"/>
<CheckBox
android:id="@+id/checkBoxBsc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BSC(IT)"/>
</LinearLayout>
OutPut->
8. Write a program using Checkbox and display message in Toast
Kotlin Code->
package [Link].ass_2_q_7
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_main)
val rmale: RadioButton=findViewById([Link])
val rfmale: RadioButton=findViewById([Link])
val cbca: CheckBox=findViewById([Link])
val cmca: CheckBox=findViewById([Link])
val cbsc: CheckBox=findViewById([Link])
[Link] {
[Link](this,"Male Selected", Toast.LENGTH_SHORT).show()
}
[Link] {
[Link](this,"Female Selected", Toast.LENGTH_SHORT).show()
}
[Link] {
var msg = ""
if ([Link]) {
msg += "BCA "
}
if ([Link]) {
msg += "MCA "
}
if ([Link]) {
msg += "BSC(IT) "
}
if ([Link]()) {
[Link](this, msg + "Selected", Toast.LENGTH_SHORT).show()
}
}
[Link] {
var msg = ""
if ([Link]) {
msg += "BCA "
}
if ([Link]) {
msg += "MCA "
}
if ([Link]) {
msg += "BSC(IT) "
}
if ([Link]()) {
[Link](this, msg + "Selected", Toast.LENGTH_SHORT).show()
}
}
[Link] {
var msg = ""
if ([Link]) {
msg += "BCA "
}
if ([Link]) {
msg += "MCA "
}
if ([Link]) {
msg += "BSC(IT) "
}
if ([Link]()) {
[Link](this, msg + "Selected", Toast.LENGTH_SHORT).show()
}
}
[Link](findViewById([Link])) { v, insets ->
val systemBars = [Link]([Link]())
[Link]([Link], [Link], [Link], [Link])
insets
}
}
}
XML Code->
<LinearLayout
xmlns:android="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"/>
<RadioButton
android:id="@+id/radiofemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"/>
</RadioGroup>
<CheckBox
android:id="@+id/checkBoxBca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BCA"/>
<CheckBox
android:id="@+id/checkBoxMca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MCA"/>
<CheckBox
android:id="@+id/checkBoxBsc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BSC(IT)"/>
</LinearLayout>
OutPut->
9. Write a program for Toggle Button and switch and print the status of the button in Toast.
KotlinCode->
package [Link].ass_2_q_9
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_main)
val tgb: ToggleButton=findViewById([Link])
val swb: Switch=findViewById([Link].switch1)
[Link] {
if ([Link]){[Link](this,"On", Toast.LENGTH_SHORT).show() }else{[Link](this,"Off", Toast.LENGTH_SHORT).show()}
}
[Link] {
if ([Link]){[Link](this,"On", Toast.LENGTH_SHORT).show()}else{[Link](this,"Off", Toast.LENGTH_SHORT).show()}
}
[Link](findViewById([Link])) { v, insets ->
val systemBars = [Link]([Link]())
[Link]([Link], [Link], [Link], [Link])
insets
}
}
}
XmlCode->
<?xml version="1.0" encoding="utf-8"?>
<[Link] xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Switch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="ToggleButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
Output->
[Link] the states name in AutoCompleteTextView and MultiAutoCompleteTextView.
KotlinCode->
package [Link].ass_2_q_10
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_main)
val atc: AutoCompleteTextView=findViewById([Link])
val matc: MultiAutoCompleteTextView=findViewById([Link])
val states=arrayOf(
"Gujarat",
"Maharashtra",
"Rajasthan",
"Punjab",
"Haryana",
"Kerala",
"Tamil Nadu",
"Karnataka",
"Uttar Pradesh",
"Madhya Pradesh")
val adapter= ArrayAdapter(this,[Link].simple_dropdown_item_1line,states)
[Link](adapter)
[Link](adapter)
[Link]([Link]())
[Link](findViewById([Link])) { v, insets ->
val systemBars = [Link]([Link]())
[Link]([Link], [Link], [Link], [Link])
insets
}
}
}
XmlCode->
<?xml version="1.0" encoding="utf-8"?>
<[Link] xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="175dp"
android:layout_height="53dp"
android:layout_marginStart="80dp"
android:layout_marginTop="108dp"
android:hint="Enter"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<MultiAutoCompleteTextView
android:id="@+id/multiAutoCompleteTextView"
android:layout_width="204dp"
android:layout_height="46dp"
android:layout_marginStart="80dp"
android:layout_marginTop="276dp"
android:hint="Enter"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>
OutPut->