Ilovepdf Merged
Ilovepdf Merged
Ilovepdf Merged
2) Provide the following information: Application name, Company domain, Project location and
Package name of application and click next.
After finishing the Activity configuration, Android Studio auto generates the activity class and other
required configuration files. Now an android project has been created. You can explore the android
project and see the simple program.
CODE
MAIN ACTIVITY,JAVA
1. package first.java.com.welcome;
2.
3. import android.support.v7.app.AppCompatActivity;
4. import android.os.Bundle;
5.
6. public class MainActivity extends AppCompatActivity {
7. @Override
8. protected void onCreate(Bundle savedInstanceState) {
9. super.onCreate(savedInstanceState);
10. setContentView(R.layout.activity_main);
11. }
12. }
To run the android application, click the run icon on the toolbar or simply press Shift + F10.
```xml
<application
android:icon="@mipmap/ic_launcher"
... >
</application>
```
- Click on `Build` > `Rebuild Project` to ensure all changes are applied.
e) Briefly describe about android activity life cycle and implement it.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate called");
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart called");
}
@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume called");
}
@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause called");
}
@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop called");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy called");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d(TAG, "onRestart called");
}
}
```
ASSIGNMENT – 2
Create an application that takes the name from a text box and shows a hello message along with the name
entered in the text box when the user clicks the OK button.
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
TextView result;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
Submit Button
*/
buttonSubmit.setOnClickListener(new View.OnClickListener() {
@Override
});
/*
Reset Button
*/
buttonReset.setOnClickListener(new View.OnClickListener() {
@Override
editName.setText("");
editPassword.setText("");
result.setText("");
editName.requestFocus();
});
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:background="#FFFF8D"
tools:context="com.example.akshay.mrcet.MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="NAME"
android:textSize="20sp"
android:layout_margin="20dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="PASSWORD"
android:layout_marginTop="38dp"
android:layout_below="@+id/textView"
android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView" />
<EditText
android:id="@+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter Name"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="@+id/editPassword"
android:layout_alignStart="@+id/editPassword" />
<EditText
android:id="@+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter Password"
android:inputType="textPassword"
android:layout_alignBottom="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="18dp"
android:layout_marginEnd="18dp" />
<Button
android:id="@+id/buttonSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView2"
android:layout_marginTop="20dp"
android:text="SUBMIT" />
<Button
android:id="@+id/buttonReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RESET"
android:layout_alignBaseline="@+id/buttonSubmit"
android:layout_alignBottom="@+id/buttonSubmit"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="143dp"
android:textSize="30sp" />
ASSIGNMENT – 3
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Main_View"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txtVw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_marginTop="20dp"
android:paddingTop="20dp"
android:textSize="24dp" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="Name"
android:inputType="text"/>
<Button
android:id="@+id/showInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:backgroundTint="@color/colorPrimary"
android:text="show"
android:textColor="@android:color/white" />
</LinearLayout>
package com.example.text_view_application
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.text_view_application.ui.theme.Text_View_ApplicationTheme
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
val showButton:Button = findViewById(R.id.showInput)
b)Create an Android app to add, and subtract two numbers supplied from a user interface having two text
boxes.
Set up the project: Create a new project in Android Studio.
Design the layout: Add two EditText views for input, two Buttons for add and subtract actions, and a
TextView for displaying the result.
Implement the logic: Add onClick listeners for the buttons to perform the add and subtract operations based
on user input and display the result.
package com.example.add_two_numbers;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
EditText number1;
EditText number2;
Button Add_button;
TextView result;
int ans=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// by ID we can use each component which id is assign in xml file
number1=(EditText) findViewById(R.id.editText_first_no);
number2=(EditText) findViewById(R.id.editText_second_no);
Add_button=(Button) findViewById(R.id.add_button);
result = (TextView) findViewById(R.id.textView_answer);
// Add_button add clicklistener
Add_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// num1 or num2 double type
// get data which is in edittext, convert it to string
// using parse Double convert it to Double type
double num1 = Double.parseDouble(number1.getText().toString());
double num2 = Double.parseDouble(number2.getText().toString());
// add both number and store it to sum
double sum = num1 + num2;
// set it ot result textview
result.setText(Double.toString(sum));
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView_answer"
android:layout_width="100dp"
android:layout_height="25dp"
android:text="0"
android:layout_marginLeft="130dp"
android:layout_marginTop="300dp"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="@+id/textView_first_no"
android:layout_width="150dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="50dp"
android:text="First number"
android:textSize="20dp"/>
<EditText
android:id="@+id/editText_first_no"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_marginLeft="200dp"
android:layout_marginTop="40dp"
android:inputType="number"
/>
<TextView
android:id="@+id/textView_second_no"
android:layout_width="150dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="100dp"
android:text="Second number"
android:textSize="20dp" />
<EditText
android:id="@+id/editText_second_no"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_marginLeft="200dp"
android:layout_marginTop="90dp"
android:inputType="number"
/>
<Button
android:id="@+id/add_button"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="200dp"
android:text="Add"/></RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"/>
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
<Button
android:id="@+id/button5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Middle Button"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Step 3: Working with the MainActivity.java file
package com.example.example1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
d)Create an Android app to multiply, and divide two numbers supplied from a user interface having two texts boxes.
Step 1: Create a new Android Application and Name it Program_Multiplication_Table with the Empty layout.
Step 2: Open the activity_main.xml (values>layout>activity_main.xml) file where we will be creating the
layout of the application.
Step 3: In activity_main.xml file add TextView, EditText, and a Button
Step 4: Assign ID to each component
Step 5: Now, open up the MainActivity file and declare the variables.
Step 6: Read the values entered in the EditText boxes using an ID that has been set in the XML code above.
Step 7: Add a click listener to the Add button
Step 8: When the Add button has been clicked we need to Multiply the values and store it in Buffer
Step 9: Then show the resultant output in the TextView by setting the buffer in the TextView.
package com.example.program_multiplication_table;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
extends AppCompatActivity
implements View.OnClickListener {
EditText editText;
Button button;
TextView result;
int ans = 0;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText)findViewById(R.id.editText);
button = (Button)findViewById(R.id.button);
result = (TextView)findViewById(R.id.textView);
button.setOnClickListener(this);
}
@Override
if(v.getId()==R.id.button) {
String fs = editText.getText().toString();
// convert it to integer
int n = Integer.parseInt(fs);
ans = (i * n);
result.setText(buffer);
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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"
tools:context=".MainActivity"
tools:layout_editor_absoluteY="25dp">
<!-- Add the button for run table logic and print result-->
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="TABLE"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/editText"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="36dp"
android:layout_marginEnd="36dp"
android:layout_marginBottom="18dp"
android:textColor="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginEnd="9dp"
android:layout_marginRight="9dp"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintEnd_toStartOf="@+id/button"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="UnknownId" />
</androidx.constraintlayout.widget.ConstraintLayout>
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
ASSIGNMENT – 4
(a) Create a screen that has input boxes foe user name, password, address, gender (radio buttons
for the male and female), Age (Numeric), Date of Birth (Date picket), State (Spinner), and a Submit
Button. On clicking the submit button, print all the below the Submit Button (any use layout).
XML CODE: -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<TextView
android:id="@+id/userNameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name:"
android:layout_marginTop="20dp"/>
<EditText
android:id="@+id/userNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/userNameLabel"
android:layout_marginTop="5dp"/>
<TextView
android:id="@+id/passwordLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"
android:layout_below="@id/userNameEditText"
android:layout_marginTop="20dp"/>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/passwordLabel"
android:layout_marginTop="5dp"
android:inputType="textPassword"/>
<TextView
android:id="@+id/genderLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender:"
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:layout_below="@id/passwordEditText"
android:layout_marginTop="20dp"/>
<RadioGroup
android:id="@+id/genderRadioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/genderLabel"
android:orientation="horizontal">
<RadioButton
android:id="@+id/maleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"/>
<RadioButton
android:id="@+id/femaleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"/>
</RadioGroup>
<TextView
android:id="@+id/dobLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date of Birth:"
android:layout_below="@id/genderRadioGroup"
android:layout_marginTop="20dp"/>
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/dobLabel"
android:layout_marginTop="5dp"/>
<TextView
android:id="@+id/stateLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="State:"
android:layout_below="@id/datePicker"
android:layout_marginTop="20dp"/>
<Spinner
android:id="@+id/stateSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:layout_below="@id/st'ateLabel"
android:layout_marginTop="5dp"/>
<Button
android:id="@+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_below="@id/stateSpinner"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"/>
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="16sp"
android:layout_below="@id/submitButton"
android:layout_marginTop="20dp"/>
</RelativeLayout>
JAVA CODE: -
package com.example.a4a;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText userNameEditText, passwordEditText;
RadioGroup genderRadioGroup;
RadioButton maleRadioButton, femaleRadioButton;
DatePicker datePicker;
Spinner stateSpinner;
TextView resultTextView;
Button submitButton;
@Override
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
resultTextView.setText(result.toString());
}
});
}
}
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
OUTPUT: -
(b) Create an Android app that will check whether the given number supplied as an input is prime
or not.
XML CODE: -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<EditText
android:id="@+id/numberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a number"
android:inputType="number"/>
<Button
android:id="@+id/checkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/numberEditText"
android:layout_centerHorizontal="true"
android:text="Check Prime"/>
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:layout_height="wrap_content"
android:layout_below="@id/checkButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"/>
</RelativeLayout>
JAVA CODE: -
package com.example.prime;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button check;
EditText text1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText numberEditText = findViewById(R.id.numberEditText);
Button checkButton = findViewById(R.id.checkButton);
TextView resultTextView = findViewById(R.id.resultTextView);
checkButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String input = numberEditText.getText().toString().trim();
if (!input.isEmpty()) {
int number = Integer.parseInt(input);
boolean isPrime = isPrime(number);
if (isPrime) {
resultTextView.setText(number + " is a prime number.");
} else {
resultTextView.setText(number + " is not a prime number.");
}
} else {
resultTextView.setText("Please enter a number.");
}
}
});
}
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
OUTPUT: -
(c) Create an Android app that will check whether a given two numbers are palindrome or not.
XML CODE: -
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:hint="Enter first number"
android:inputType="number" />
<EditText
android:id="@+id/secondNumberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/firstNumberEditText"
android:layout_marginTop="16dp"
android:hint="Enter second number"
android:inputType="number" />
<Button
android:id="@+id/checkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/secondNumberEditText"
android:layout_marginTop="16dp"
android:text="Check" />
<TextView
android:id="@+id/resultTextView"
android:layout_width="266dp"
android:layout_height="137dp"
android:gravity="center"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="79dp"
android:layout_marginTop="297dp"
android:layout_marginEnd="82dp"
android:layout_marginBottom="313dp"
android:text="TextView" />
</RelativeLayout>
JAVA CODE: -
package com.example.palindrome;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
}
left++;
right--;
}
return true;
}
}
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
OUTPUT: -
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
ASSIGNMENT – 5
XML CODE: -
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:padding="8dp"
android:layout_column="5"/>
<TextView
android:layout_height="match_parent"
android:layout_column="6"
android:padding="8dp"
android:text="Gread"
android:textStyle="bold" />
</TableRow>
<TableRow>
<TextView
android:text="Ram"
android:padding="8dp"
android:layout_column="1"/>
<TextView
android:text="25"
android:padding="8dp"
android:layout_column="2"/>
<TextView
android:text="Male"
android:padding="8dp"
android:layout_column="3"/>
<TextView
android:text="BBA"
android:padding="8dp"
android:layout_column="4"/>
<TextView
android:text="1001"
android:padding="8dp"
android:layout_column="5"/>
<TextView
android:text="A+"
android:padding="8dp"
android:layout_column="6"/>
</TableRow>
<TableRow>
<TextView
android:text="Rahul"
android:padding="8dp"
android:layout_column="1"/>
<TextView
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:text="30"
android:padding="8dp"
android:layout_column="2"/>
<TextView
android:text="Male"
android:padding="8dp"
android:layout_column="3"/>
<TextView
android:text="MCA"
android:padding="8dp"
android:layout_column="4"/>
<TextView
android:text="1002"
android:padding="8dp"
android:layout_column="5"/>
<TextView
android:text="A"
android:padding="8dp"
android:layout_column="6"/>
</TableRow>
<TableRow>
<TextView
android:text="Sumit"
android:padding="8dp"
android:layout_column="1"/>
<TextView
android:text="30"
android:padding="8dp"
android:layout_column="2"/>
<TextView
android:text="Male"
android:padding="8dp"
android:layout_column="3"/>
<TextView
android:text="BCA"
android:padding="8dp"
android:layout_column="4"/>
<TextView
android:text="1003"
android:padding="8dp"
android:layout_column="5"/>
<TextView
android:text="A+"
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:padding="8dp"
android:layout_column="6"/>
</TableRow>
</TableLayout>
</LinearLayout>
JAVA CODE: -
package com.example.table_layout;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
OUTPUT: -
(b)Create an android app to implement table layout and button click event.
XML CODE: -
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:text="Name"
android:textStyle="bold"
android:padding="8dp"/>
<TextView
android:id="@+id/name"
android:padding="8dp"/>
</TableRow>
<TableRow>
<TextView
android:text="Age"
android:textStyle="bold"
android:padding="8dp"/>
<TextView
android:id="@+id/age"
android:padding="8dp"/>
</TableRow>
<TableRow>
<TextView
android:text="DEPT"
android:textStyle="bold"
android:padding="8dp"/>
<TextView
android:id="@+id/dept"
android:padding="8dp"/>
</TableRow>
</TableLayout>
<Button
android:id="@+id/updateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tableLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Update Data"/>
</RelativeLayout>
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
JAVA CODE: -
package com.example.button_checking;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView name,age,dept;
private Button updateButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.name);
age = findViewById(R.id.age);
dept = findViewById(R.id.dept);
updateButton = findViewById(R.id.updateButton);
updateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateData();
}
});
}
private void updateData() {
name.setText("Puja Kumari");
age.setText("22");
dept.setText("BCA");
}
}
OUTPUT: -
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
JAVA CODE: -
package com.example.armstrong_number;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
OUTPUT: -
(d) Develop an Android Application that can calculate the sum of digit of a given number.
XML CODE: -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<EditText
android:id="@+id/numberInput"
android:layout_width="match_parent"
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:layout_height="wrap_content"
android:hint="Enter a number"
android:inputType="number" />
<Button
android:id="@+id/calculateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/numberInput"
android:layout_centerHorizontal="true"
android:text="Calculate" />
<TextView
android:id="@+id/resultText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/calculateButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Sum of Digits:"
android:textSize="20sp" />
</RelativeLayout>
JAVA CODE: -
package com.example.sum_of_dig;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText numberInput = findViewById(R.id.numberInput);
Button calculateButton = findViewById(R.id.calculateButton);
final TextView resultText = findViewById(R.id.resultText);
calculateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
OUTPUT: -
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
ASSIGNMENT – 6
XML CODE: -
JAVA CODE: -
package com.example.implicit_intent;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private StringBuilder phoneNumber = new StringBuilder();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnCall = findViewById(R.id.btn_call);
View.OnClickListener numberClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Button button = (Button) v;
phoneNumber.append(button.getText().toString());
}
};
findViewById(R.id.btn_1).setOnClickListener(numberClickListener);
findViewById(R.id.btn_0).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
phoneNumber.append("0");
}
});
btnCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String number = phoneNumber.toString();
Uri uri = Uri.parse("tel:" + number
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
OUTPUT: -
XML CODE: -
JAVA CODE: -
import android.content.Intent;
import android.os.Bundle;
import android.view.View; import
android.widget.Button; import
android.widget.EditText; import
android.widget.TextView; import
android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText n;
EditText p;
Button submit;
@Override
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
OUTPUT: -
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
ASSIGNMENT – 7
a) Create an Android App that will check whether given user name and password matches with the
predefine user name and password.
XML CODE: -
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:layout_height="47dp"
android:text="Check"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.423" />
</androidx.constraintlayout.widget.ConstraintLayout>
JAVA CODE: -
package com.example.pass_checking;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle; import
android.view.View; import
android.widget.Button; import
android.widget.EditText; import
android.widget.TextView; import
android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText n;
EditText p;
Button submit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
n = findViewById(R.id.n);
p = findViewById(R.id.p);
submit = findViewById(R.id.submit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = n.getText().toString();
String pass = p.getText().toString();
if(name.equals("admin")&& pass.equals("12345"))
{
Intent intent = new Intent(MainActivity.this,page2.class);
startActivity(intent);
}
else if (name.equals("") || pass.equals(""))
{
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
OUTPUT: -
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
ASSIGNMENT – 8
XML CODE: -
JAVA CODE: -
package com.example.fragmentation;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button b1,b2,b3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.b1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainerView4, News.class,null)
.setReorderingAllowed(true)
.addToBackStack("name")
.commit();
}
});
b2 = findViewById(R.id.b2);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainerView4,sports.class,null)
.setReorderingAllowed(true)
.addToBackStack("name")
.commit();
}
});
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
b3 = findViewById(R.id.b3);
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainerView4,shopping.class,null)
.setReorderingAllowed(true)
.addToBackStack("name")
.commit();
}
});
}
}
OUTPUT: -
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
ASSIGNMENT – 9
XML CODE: -
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="2"
android:textSize="20sp" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1" android:text="3"
android:textSize="20sp" />
<Button
android:id="@+id/buttonAdd"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="+"
android:textSize="20sp" />
<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="4"
android:textSize="20sp" />
<Button
android:id="@+id/button5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="5"
android:textSize="20sp" />
<Button
android:id="@+id/button6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="6"
android:textSize="20sp" />
<Button
android:id="@+id/buttonSubtract"
android:layout_width="0dp"
android:layout_height="wrap_content"
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:layout_columnWeight="1"
android:text="-"
android:textSize="20sp" />
<Button
android:id="@+id/button7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="7"
android:textSize="20sp" />
<Button
android:id="@+id/button8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="8"
android:textSize="20sp" />
<Button
android:id="@+id/button9"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="9"
android:textSize="20sp" />
<Button
android:id="@+id/buttonMultiply"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="*"
android:textSize="20sp" />
<Button
android:id="@+id/buttonClear"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnSpan="2"
android:layout_columnWeight="2"
android:text="C"
android:textSize="20sp" />
<Button
android:id="@+id/button0"
android:layout_width="0dp"
android:layout_height="wrap_content"
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
android:layout_columnWeight="1"
android:text="0"
android:textSize="20sp" />
<Button
android:id="@+id/buttonDecimal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="."
android:textSize="20sp" />
<Button
android:id="@+id/buttonDivide"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:text="/"
android:textSize="20sp" />
<Button
android:id="@+id/buttonEqual"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnSpan="4"
android:layout_columnWeight="4"
android:text="="
android:textSize="20sp" />
</GridLayout>
</LinearLayout>
JAVA CODE: -
package com.example.calulator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView textViewResult;
private StringBuilder currentNumber;
private double operand1, operand2;
private char operator;
private Button clr,buttonDecimal;
@Override
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewResult = findViewById(R.id.textViewResult);
currentNumber = new StringBuilder();
for (int i = 0; i < 10; i++) {
int id = getResources().getIdentifier("button" + i, "id", getPackageName());
Button button = findViewById(id);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
currentNumber.append(((Button) v).getText());
textViewResult.setText(currentNumber.toString());
}
});
}
findViewById(R.id.buttonAdd).setOnClickListener(operatorClickListener);
findViewById(R.id.buttonSubtract).setOnClickListener(operatorClickListener);
findViewById(R.id.buttonMultiply).setOnClickListener(operatorClickListener);
findViewById(R.id.buttonDivide).setOnClickListener(operatorClickListener);
findViewById(R.id.buttonDecimal).setOnClickListener(operatorClickListener);
findViewById(R.id.buttonClear).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
currentNumber.setLength(0
);
operand1=0;
operand2=0;
operator = '\0';
textViewResult.setText(" ");
}
});
findViewById(R.id.buttonEqual).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!textViewResult.getText().toString().isEmpty()) {
operand2 = Double.parseDouble(currentNumber.toString());
double result = performOperation();
textViewResult.setText(String.valueOf(result));
currentNumber.setLength(0);
currentNumber.append(result);
}
}
});
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
}
private View.OnClickListener operatorClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!textViewResult.getText().toString().isEmpty()) {
operand1 = Double.parseDouble(currentNumber.toString());
currentNumber.setLength(0); // Clear the StringBuilder for next number input
operator = ((Button) v).getText().charAt(0);
}
}
};
private double performOperation() {
double result = 0;
switch (operator) {
case '+':
result = operand1 + operand2;
break;
case '-':
result = operand1 - operand2;
break;
case '*':
result = operand1 * operand2;
break;
case '/':
if (operand2 != 0) {
result = operand1 / operand2;
} else {
textViewResult.setText("Error");
}
break;
}
return result;
}
}
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021
BCAD691A
Mobile Application Development
Session 2021
Academic Session 2023-2024
OUTPUT: -
Puja Kumari
BWU/BCA/21/219
SEC- D
BCA 2021