Android Lab Vinay
Android Lab Vinay
DEHRADUN
Practical file
on
ANDROID STUDIO PROGRAMMING
For the fulfilment of
BACHELORS OF COMPUTER APPLICATION
(SESSION- 2023-2024)
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textAllCaps="true"
android:textColor="@color/design_default_color_error"
android:textSize="40sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.492"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.469" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.vinayexam.question1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Question1"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to change the layout color on
button click.
OBJECTIVE- Create an Android app that enables users to change the layout color with a
button click, providing an intuitive and interactive user interface experience.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
tools:context=".MainActivity"
android:id="@+id/linearlayout">
<Button
android:id="@+id/redbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RED"
tools:layout_editor_absoluteX="36dp"
tools:layout_editor_absoluteY="236dp" />
<Button
android:id="@+id/greenbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GREEN"
tools:layout_editor_absoluteX="337dp"
tools:layout_editor_absoluteY="236dp" />
</LinearLayout>
MainActivity.java
package com.vinayexam.bgcoloronbuttonclick;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
redbutton = findViewById(R.id.redbutton);
greenbutton = findViewById(R.id.greenbutton);
layout = findViewById(R.id.linearlayout);
redbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
layout.setBackgroundColor(Color.RED);
}
});
greenbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
layout.setBackgroundColor(Color.GREEN);
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.BgColorOnButtonClick"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to change the color of written
text on button click.
OBJECTIVE- Develop an Android application that enables users to change the color of
written text through a button click, enhancing text customization and user experience.
activity_main.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Color"
android:layout_below="@id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="16sp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="AANCHAL JEENA"
android:textSize="34sp" />
</RelativeLayout>
MainActivity.java
package com.vinayexam.changebuttontextcolor;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
Button button;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button3);
textView = findViewById(R.id.textView2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textView.setTextColor(getResources().getColor(R.color.red));
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ChangeButtonTextColor"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- . Develop an android application to demonstrate Event
Listener and Event Handlers.
OBJECTIVE- Create an Android app showcasing Event Listener and Event Handlers
functionality to enhance user interaction and responsiveness, fostering a deeper
understanding of mobile app development.
activity_main.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView"
android:layout_marginTop="30dp"
android:layout_centerInParent="true"
android:text="Click Me"
android:textSize="20dp" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Event will appear here"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:layout_marginTop="16dp"
android:textSize="30dp" />
</RelativeLayout>
MainActivity.java
package com.vinayexam.eventlistenerandeventhandler;
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 {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
textView = findViewById(R.id.textView);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textView.setText("Hello There WELCOME!");
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.EventListenerAndEventHandler"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to depict android’s activity life
cycle.
OBJECTIVE- Create an educational Android app illustrating the Android Activity Lifecycle
through interactive visuals and explanations, enabling users to understand the core concepts
of app navigation and state management.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:textStyle="bold"
android:textSize="30dp"
android:textColor="@color/cyan"/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.vinayexam.activitylifecycleusinglog;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate: Activity created");
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart: Activity started");
}
@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume: Activity resumed");
}
@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause: Activity paused");
}
@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop: Activity Stopped");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy: Activity destroyed");
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ActivityLifeCycleUsingLog"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to take the input of two
numbers and print their addition.
OBJECTIVE- Design and develop an Android app that efficiently accepts two numerical
inputs from users and accurately calculates their sum, providing a user-friendly addition
functionality.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
android:padding="16sp"
tools:context=".MainActivity"
android:background="@color/yellow">
<EditText
android:id="@+id/number1EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter First Number"
android:inputType="number"
android:textSize="25sp"
android:layout_marginTop="16sp"
/>
<EditText
android:id="@+id/number2EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Second Number"
android:inputType="number"
android:textSize="25sp"
android:layout_marginTop="16sp"
/>
<TextView
android:layout_marginLeft="120sp"
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result Here"
android:textSize="25sp"
android:textStyle="bold"
android:layout_marginTop="16sp" />
<Button
android:layout_marginLeft="100sp"
android:id="@+id/calculateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate Sum"
android:textSize="20sp"
android:layout_marginTop="16sp"
/>
</LinearLayout>
MainActivity.java
package com.vinayexam.sumof2numbers;
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
number1EditText = findViewById(R.id.number1EditText);
number2EditText = findViewById(R.id.number2EditText);
calculateButton= findViewById(R.id.calculateButton);
resultTextView = findViewById(R.id.resultTextView);
calculateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String num1Str = number1EditText.getText().toString();
String num2Str = number2EditText.getText().toString();
try {
double num1 = Double.parseDouble(num1Str);
double num2 = Double.parseDouble(num2Str);
double sum = num1 + num2;
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SumOf2Numbers"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to create basic calculator.
OBJECTIVE- Develop an Android application that combines a basic calculator offering
users a versatile tool for performing simple arithmetic calculations.
activity_main.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cyan"
tools:context=".MainActivity">
<EditText
android:id="@+id/etn1"
android:layout_width="match_parent"
android:layout_height="50sp"
android:ems="15"
android:layout_marginTop="10sp"
android:hint="Enter Number 1"
android:inputType="number"
tools:layout_editor_absoluteX="93sp"
tools:layout_editor_absoluteY="65sp"
/>
<EditText
android:layout_below="@id/etn1"
android:id="@+id/etn2"
android:layout_width="match_parent"
android:layout_height="50sp"
android:ems="15"
android:layout_marginTop="10sp"
android:hint="Enter Number 2"
android:inputType="number"
tools:layout_editor_absoluteX="98sp"
tools:layout_editor_absoluteY="150sp"
/>
<TextView
android:layout_below="@id/etn2"
android:layout_marginTop="20sp"
android:layout_centerInParent="true"
android:id="@+id/textViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RESULT"
android:textSize="24sp"
android:textStyle="bold|italic"
tools:layout_editor_absoluteX="164sp"
tools:layout_editor_absoluteY="269sp"
/>
<Button
android:layout_below="@id/textViewResult"
android:layout_marginTop="16sp"
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="btnadd"
android:text="ADD"
tools:layout_editor_absoluteX="37sp"
tools:layout_editor_absoluteY="338sp"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="187sp"
android:onClick="btnsub"
android:text="SUB"
tools:layout_editor_absoluteX="282sp"
tools:layout_editor_absoluteY="336sp" />
<Button
android:layout_below="@id/button"
android:layout_marginTop="16sp"
android:layout_marginLeft="90sp"
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="btnmul"
android:text="MUL"
tools:layout_editor_absoluteX="85sp"
tools:layout_editor_absoluteY="424sp"
/>
<Button
android:layout_alignParentRight="true"
android:layout_marginTop="252sp"
android:layout_marginRight="90sp"
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="btndiv"
android:text="DIV"
tools:layout_editor_absoluteX="240sp"
tools:layout_editor_absoluteY="424sp" />
</RelativeLayout>
MainActivity.java
package com.vinayexam.simplecalculator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etn1 = (EditText) findViewById(R.id.etn1);
etn2 = (EditText) findViewById(R.id.etn2);
textViewResult = (TextView) findViewById(R.id.textViewResult);
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SimpleCalculator"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to create scientific calculator.
OBJECTIVE- Develop an Android application that combines a basic and scientific
calculator, offering users a versatile tool for performing both simple arithmetic calculations
and complex scientific functions.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:weightSum="10"
tools:context=".MainActivity">
<TextView
android:id="@+id/tvsec"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#000"
android:text=""
android:textStyle="bold"
android:textColor="#f6f6f6"
android:textSize="30sp"
android:textAlignment="viewEnd"
android:padding="10dp"
android:gravity="bottom"
android:maxLines="1"
android:layout_weight="1"
tools:ignore="RtlCompat">
</TextView>
<TextView
android:id="@+id/tvmain"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#000"
android:text=""
android:textStyle="bold"
android:textColor="#fff"
android:textSize="50sp"
android:textAlignment="viewEnd"
android:padding="10dp"
android:gravity="bottom"
android:maxLines="1"
android:layout_weight="1"
tools:ignore="RtlCompat">
</TextView>
<LinearLayout
android:layout_weight="8"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp">
<LinearLayout
android:orientation="vertical"
android:layout_weight="7"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:weightSum="4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/bac"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="AC"
android:textStyle="bold"
android:textSize="30sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="C"
android:textStyle="bold"
android:textSize="30sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bb1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="("
android:textStyle="bold"
android:textSize="30sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bb2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=")"
android:textStyle="bold"
android:textSize="30sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:weightSum="5"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/bsin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="sin"
android:textAllCaps="false"
android:textStyle="bold"
android:textSize="16sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bcos"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="cos"
android:textAllCaps="false"
android:textStyle="bold"
android:textSize="15sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/btan"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="tan"
android:textAllCaps="false"
android:textStyle="bold"
android:textSize="16sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/blog"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="log"
android:textAllCaps="false"
android:textStyle="bold"
android:textSize="16sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bln"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="ln"
android:textAllCaps="false"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:weightSum="5"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/bfact"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="x!"
android:textAllCaps="false"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bsquare"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="x^"
android:textAllCaps="false"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bsqrt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="√"
android:textAllCaps="false"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/binv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="1/x"
android:textAllCaps="false"
android:textStyle="bold"
android:textSize="16sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bdiv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="÷"
android:textAllCaps="false"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:weightSum="4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/b7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="7"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/white"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/b8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="8"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/white"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/b9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="9"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/white"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bmul"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="×"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:weightSum="4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/b4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="4"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/white"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/b5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="5"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/white"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/b6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="6"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/white"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bmin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="-"
android:textStyle="bold"
android:textSize="30sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:weightSum="4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/b1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="1"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/white"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/b2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="2"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/white"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/b3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="3"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/white"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bplus"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="+"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:weightSum="4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/bpi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="𝝅"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/white"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/b0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="0"
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/white"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bdot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="."
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/white"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/bequal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="="
android:textStyle="bold"
android:textSize="21sp"
android:background="#000"
android:textColor="@color/yellow"
android:layout_weight="1">
</Button>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
MainActivity.java
package com.vinayexam.scientificcalculator;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button
b1,b2,b3,b4,b5,b6,b7,b8,b9,b0,bdot,bpi,bequal,bplus,bmin,bmul,bdiv,binv,bsqrt,bsquare,
bfact,bln,blog,btan,bcos,bsin,bb1,bb2,bc,bac;
TextView tvmain,tvsec;
String pi = "3.14159265";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.b1);
b2 = findViewById(R.id.b2);
b3 = findViewById(R.id.b3);
b4 = findViewById(R.id.b4);
b5 = findViewById(R.id.b5);
b6 = findViewById(R.id.b6);
b7 = findViewById(R.id.b7);
b8 = findViewById(R.id.b8);
b9 = findViewById(R.id.b9);
b0 = findViewById(R.id.b0);
bpi = findViewById(R.id.bpi);
bdot = findViewById(R.id.bdot);
bequal = findViewById(R.id.bequal);
bplus = findViewById(R.id.bplus);
bmin = findViewById(R.id.bmin);
bmul = findViewById(R.id.bmul);
bdiv = findViewById(R.id.bdiv);
binv = findViewById(R.id.binv);
bsqrt = findViewById(R.id.bsqrt);
bsquare = findViewById(R.id.bsquare);
bfact = findViewById(R.id.bfact);
bln = findViewById(R.id.bln);
blog = findViewById(R.id.blog);
btan = findViewById(R.id.btan);
bsin = findViewById(R.id.bsin);
bcos = findViewById(R.id.bcos);
bb1 = findViewById(R.id.bb1);
bb2 = findViewById(R.id.bb2);
bc = findViewById(R.id.bc);
bac = findViewById(R.id.bac);
tvmain = findViewById(R.id.tvmain);
tvsec = findViewById(R.id.tvsec);
//onclick listeners
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"1");
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"2");
}
});
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"3");
}
});
b4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"4");
}
});
b5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"5");
}
});
b6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"6");
}
});
b7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"7");
}
});
b8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"8");
}
});
b9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"9");
}
});
b0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"0");
}
});
bdot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+".");
}
});
bac.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText("");
tvsec.setText("");
}
});
bc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String val = tvmain.getText().toString();
val = val.substring(0, val.length() - 1);
tvmain.setText(val);
}
});
bplus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"+");
}
});
bmin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"-");
}
});
bmul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"×");
}
});
bdiv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"÷");
}
});
bsqrt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String val = tvmain.getText().toString();
double r = Math.sqrt(Double.parseDouble(val));
tvmain.setText(String.valueOf(r));
}
});
bb1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"(");
}
});
bb2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+")");
}
});
bpi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvsec.setText(bpi.getText());
tvmain.setText(tvmain.getText()+pi);
}
});
bsin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"sin");
}
});
bcos.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"cos");
}
});
btan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"tan");
}
});
binv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"^"+"(-1)");
}
});
bfact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int val = Integer.parseInt(tvmain.getText().toString());
int fact = factorial(val);
tvmain.setText(String.valueOf(fact));
tvsec.setText(val+"!");
}
});
bsquare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double d = Double.parseDouble(tvmain.getText().toString());
double square = d*d;
tvmain.setText(String.valueOf(square));
tvsec.setText(d+"²");
}
});
bln.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"ln");
}
});
blog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvmain.setText(tvmain.getText()+"log");
}
});
bequal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String val = tvmain.getText().toString();
String replacedstr = val.replace('÷','/').replace('×','*');
double result = eval(replacedstr);
tvmain.setText(String.valueOf(result));
tvsec.setText(val);
}
});
//factorial function
int factorial(int n)
{
return (n==1 || n==0) ? 1 : n*factorial(n-1);
}
void nextChar() {
ch = (++pos < str.length()) ? str.charAt(pos) : -1;
}
double parse() {
nextChar();
double x = parseExpression();
if (pos < str.length()) throw new RuntimeException("Unexpected: " + (char)ch);
return x;
}
double parseExpression() {
double x = parseTerm();
for (;;) {
if (eat('+')) x += parseTerm(); // addition
else if (eat('-')) x -= parseTerm(); // subtraction
else return x;
}
}
double parseTerm() {
double x = parseFactor();
for (;;) {
if (eat('*')) x *= parseFactor(); // multiplication
else if (eat('/')) x /= parseFactor(); // division
else return x;
}
}
double parseFactor() {
if (eat('+')) return parseFactor(); // unary plus
if (eat('-')) return -parseFactor(); // unary minus
double x;
int startPos = this.pos;
if (eat('(')) { // parentheses
x = parseExpression();
eat(')');
} else if ((ch >= '0' && ch <= '9') || ch == '.') { // numbers
while ((ch >= '0' && ch <= '9') || ch == '.') nextChar();
x = Double.parseDouble(str.substring(startPos, this.pos));
} else if (ch >= 'a' && ch <= 'z') { // functions
while (ch >= 'a' && ch <= 'z') nextChar();
String func = str.substring(startPos, this.pos);
x = parseFactor();
if (func.equals("sqrt")) x = Math.sqrt(x);
else if (func.equals("sin")) x = Math.sin(Math.toRadians(x));
else if (func.equals("cos")) x = Math.cos(Math.toRadians(x));
else if (func.equals("tan")) x = Math.tan(Math.toRadians(x));
else if (func.equals("log")) x = Math.log10(x);
else if (func.equals("ln")) x = Math.log(x);
else throw new RuntimeException("Unknown function: " + func);
} else {
throw new RuntimeException("Unexpected: " + (char)ch);
}
return x;
}
}.parse();
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ScientificCalculator"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to create two buttons and
switch between images on button click.
OBJECTIVE- Create an Android application with two buttons that toggle between images
upon button press, providing a user-friendly and interactive image-switching experience.
activity_main.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:background="@color/green"
tools:context=".MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Image 1"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Image 2"
android:layout_below="@+id/button1"
/>
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/button2"
android:layout_marginTop="16dp"
android:src="@drawable/image1"
/>
</RelativeLayout>
MainActivity.java
package com.vinayexam.imagechangeonbuttonclick;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView);
button1 = findViewById(R.id.button1);
button2 = findViewById(R.id.button2);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
imageView.setImageResource(R.drawable.image1);
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
imageView.setImageResource(R.drawable.image2);
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ImageChangeOnButtonClick"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to create a list of Books and
their published year using array adapter.
OBJECTIVE- Develop an Android application with an ArrayAdapter to efficiently manage
and display a list of books along with their respective publication years.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:dividerHeight="1dp"
android:background="@color/green"
android:divider="#E41E0F"/>
</LinearLayout>
MainActivity.java
package com.vinayexam.booklistappusingarrayadapter;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.listView);
String[] books = {"The Pragmatic Programmer", "Programming Pearls", "The Clean
Coder",
"The Art of Computer", "Coders At Work"};
String[] years = {"2000", "2005", "2010", "2015", "2018"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_2, android.R.id.text1, books);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
listView.setAdapter(adapter);
listView.setOnItemClickListener((parent, view, position, id) -> {
String itemValue = (String) listView.getItemAtPosition(position);
Toast Toast = null;
Toast.makeText(getApplicationContext(), "Book: " + itemValue + "\nYear: " +
years[position], Toast.LENGTH_LONG).show();
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.BookListAppUsingArrayAdapter"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to create four radio buttons
of two different groups. Change the layout color on selecting any option from first radio
group. Change the image on selecting any option from second radio group.
OBJECTIVE- Design and implement an Android app with two distinct radio button groups,
enabling layout color changes upon selection in the first group and image updates in the
second group.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<RadioGroup
android:id="@+id/radioGroupColor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/radioRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red" />
<RadioButton
android:id="@+id/radioBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blue" />
</RadioGroup>
<RadioGroup
android:id="@+id/radioGroupImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/radioCat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cat" />
<RadioButton
android:id="@+id/radioDog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dog" />
</RadioGroup>
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/cat_image" />
</LinearLayout>
MainActivity.java
package com.vinayexam.fourradiobuttons;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioGroupColor = findViewById(R.id.radioGroupColor);
radioGroupImage = findViewById(R.id.radioGroupImage);
imageView = findViewById(R.id.imageView);
radioGroupColor.setOnCheckedChangeListener(new
RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.radioRed) {
findViewById(android.R.id.content).setBackgroundColor(Color.RED);
} else if (checkedId == R.id.radioBlue) {
findViewById(android.R.id.content).setBackgroundColor(Color.BLUE);
}
}
});
radioGroupImage.setOnCheckedChangeListener(new
RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.radioCat) {
imageView.setImageResource(R.drawable.cat_image);
} else if (checkedId == R.id.radioDog) {
imageView.setImageResource(R.drawable.default_image);
}
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.FourRadioButtons"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to display toast message of
different length on button click.
OBJECTIVE- Create an Android app that responds to button clicks by displaying toast
messages of varying durations, providing a practical and interactive user experience.
activity_main.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">
<Button
android:id="@+id/buttonShowToast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast"
android:textSize="30dp"
android:layout_centerInParent="true"
/>
</RelativeLayout>
MainActivity.java
package com.vinayexam.toastmessage;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonShowToast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Short Toast",
Toast.LENGTH_SHORT).show();
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ToastMessage"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<AutoCompleteTextView
android:id="@+id/autoCompleteTextViewUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username or Email"
android:textSize="25dp"
android:padding="16dp"/>
<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:textSize="25dp"
android:padding="16dp"
android:layout_marginTop="10dp"/>
<Button
android:id="@+id/buttonLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textSize="25dp"
android:layout_marginTop="10dp"/>
</LinearLayout>
MainActivity.java
package com.vinayexam.autocompletetext;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autoCompleteTextViewUsername =
findViewById(R.id.autoCompleteTextViewUsername);
editTextPassword = findViewById(R.id.editTextPassword);
buttonLogin = findViewById(R.id.buttonLogin);
buttonLogin.setOnClickListener(v -> {
String username = autoCompleteTextViewUsername.getText().toString();
String password = editTextPassword.getText().toString();
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AutoCompleteText"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to display a pop-up message
on activity when toggle button’s state is changed.
OBJECTIVE- Create an Android app that presents a pop-up notification upon toggling a
button's state change within an activity, enhancing user interaction and feedback.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="On"
android:textOff="Off"
android:textSize="25dp"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
MainActivity.java
package com.vinayexam.popupmessageontooglebutton;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.ToggleButton;
import androidx.appcompat.app.AppCompatActivity;
toggleButton = findViewById(R.id.toggleButton);
toggleButton.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
showToast("Toggle is ON");
} else {
showToast("Toggle is OFF");
}
}
});
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PopUpMessageOnToogleButton"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to create an image gallery
using grid view.
OBJECTIVE- Objective: Develop an Android application to efficiently organize and display
images in a grid view, providing users with an intuitive and visually appealing image gallery
experience.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:columnWidth="100dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
</LinearLayout>
MainActivity.java
package com.vinayexam.galleryusinggridview;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = findViewById(R.id.gridView);
ImageAdapter adapter = new ImageAdapter(this);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
String imageName = getResources().getResourceEntryName((int) id);
Toast.makeText(MainActivity.this, "Clicked: " + imageName,
Toast.LENGTH_SHORT).show();
}
});
}
}
ImageAdapter.java
package com.vinayexam.galleryusinggridview;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
@Override
public int getCount() {
return imageIds.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return imageIds[position];
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(300, 300)); //
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8); // Set padding
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(imageIds[position]);
return imageView;
}
};
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.GalleryUsingGridView"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to create an audio player
using onClick attribute.
OBJECTIVE- Create an Android audio player application with clickable functionality,
allowing users to play audio files, utilizing the onClick attribute for seamless user interaction
and playback control.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/black"
android:gravity="center">
<Button
android:id="@+id/playButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play"
android:onClick="playAudio"
android:textSize="30dp"
android:layout_margin="16dp"/>
<Button
android:id="@+id/pauseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pause"
android:textSize="30dp"
android:layout_margin="16dp"
android:onClick="pauseAudio" />
<Button
android:id="@+id/stopButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
android:textSize="30dp"
android:layout_margin="16dp"
android:onClick="stopAudio" />
</LinearLayout>
MainActivity.java
package com.vinayexam.musicplayer;
import androidx.appcompat.app.AppCompatActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MusicPlayer"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:
NAME-Aanchal Jeena
COURSE-BCA SEM-5TH
ROLL NO-01
SUBJECT-ANDROID PROGRAMMING
PROBLEM STATEMENT:- Develop an android application to create a video player using
media controller widgets.
OBJECTIVE- Design and build an Android video player application featuring media
controller widgets for seamless playback and user-friendly controls, enhancing the media
consumption experience.
activity_main.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/v1"
/>
</RelativeLayout>
MainActivity.java
package com.vinayexam.videoplayer;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
v1 = findViewById(R.id.v1);
String path = "android.resource://"+getPackageName()+"/"+R.raw.sample;
Uri u = Uri.parse(path);
v1.setVideoURI(u);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.VideoPlayer"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT: