Android Practical File
Android Practical File
Android Practical File
Ludhiana
Android Programming
PRACTICAL FILE
NAME: Saurav
SUBJECT: Android Programming
UNIV.ROLL.NO: 2123397
SUBMITTED TO: Ms. Ishita Malhotra
OFFICIAL E-MAIL ADDRESS: [email protected]
Table of Contents
Sr No Topics Page No
10 Design an application for Database connectivity using SQLite database. Create table 24 – 25
stud_details and perform all possible queries of insertion, deletion, updation on the
click of buttonsusing SQLite in Android Studio.
11 Design a billing application using Check Boxes in Android Studio for a bookstore. 26 – 27
12 Working with Calendar View in Android Studio. 28
13 Design an application using Seek Bar in Android Studio. 29
Task 1: Installation of Java, android Framework
1. Download Java for Windows: -
1
Where to install Java on Windows?
2
Set The Java Path
3
Installation of Android Framework: -
Verify that environment variable JAVA_HOME is set to the JDK installation directory by
the using command “set JAVA_HOME “.
Check the system requirements for Android Studio and SDK
(https://developer.android.com/studio#Requirements).
Go to “Android Studio” https://developer.android.com/studio ⇒ Click “Download Android
Studio for Windows 64-bit.
Run .exe step >> Launch Android Studio. Continue to the Next Step.
4
Click Apply. Android Studio starts installing your selected packages. After completing the
installation, the Status of the installed packages and tools changes from Not Installed to
Installed.
5
Task 2: Android SDK Manager and all its components
Android SDK stands for Android Software Development Kit which is developed by
Google for Android Platform. With the help of Android SDK, we can create android
Apps easily.
Android Emulator.
6
Android SDK build tools are used for building actual binaries of Android App. The main
functions of Android SDK Build tools are built, debug, run and test Android applications.
The latest version of the Android SDK Build tool is 30.0.3. While downloading or updating
Android in our System, one must ensure that its latest version is downloaded in SDK
Components.
3. Android Emulator: -
An Android Emulator is a device that simulates an Android device on your system. Suppose
we want to run our android application that we code. One option is that we will run this on
our Android Mobile by Enabling USB Debugging on our mobile. Another option is using
Android Emulator. In Android Emulator the virtual android device is shown on our system
on which we run the Android application that we code.
In Android Virtual Emulator all functions that are feasible on real Android mobile is works on virtual
Device like:
7
Android Debug Bridge (ADB) is a command-line tool that helps to communicate with the
device. It allows us to perform an action such as Installing App and Debugging App etc.
Fast boot allows you to flash a device with a new system image.
Systane tools help to collect and inspect timing information. It is very crucial for App
Debugging.
5. SDK Platforms: -
For Each Android Software, one SDK platform is available as shown below:
In SDK Update Sites, some sites are embedded in it which will check for
Android SDK Updates Tools. In this, one must ensure we don’t unclick the
button below because these are checked by default which will check for updates
if we unclick it then it doesn’t check updates for those.
8
Task 3: Program based on the overriding in Java
package Saurav;
// Superclass
class Vehicle {
void start () {
System.out.println("Vehicle is starting...");
}
}
// Subclass Car
class Car extends Vehicle {
@Override
void start () {
System.out.println("Car is starting...");
}
void drive () {
System.out.println("Car is in motion!");
}
}
public class Method_Overriding {
public static void main (String [] args) {
Vehicle myVehicle = new Vehicle ();
Car myCar = new Car();
// Call the overridden methods
myVehicle.start();
myCar.start();
// Call the specific method of the Car class
myCar.drive();
}
}
9
Task 4: Program based on the Constructor Overloading
in Java
package Saurav;
class Student {
private String name;
private int age;
private String course;
10
// Display student details
student1.displayDetails();
student2.displayDetails();
student3.displayDetails();
}
}
11
Task 5: Program based on the Classes in Java
package Saurav;
import java.util.Scanner;
class students {
int rn;
String nm;
String dept;
Scanner ob = new Scanner(System.in);
}
public class Classes
{
public static void main(String[] args) {
students sd;
sd = new students();
sd.input();
sd.disp();
}
}
12
Task 6: Design an Application (Calculator) based on
Edit Text, Text Boxes, and Button
activity_main.xml File: -
<?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"
android:padding="16dp"
tools:context=".MainActivity">
<EditText
android:id="@+id/editTextNumber1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="Enter number 1"/>
<EditText
android:id="@+id/editTextNumber2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextNumber1"
android:layout_marginTop="8dp"
android:inputType="numberDecimal"
android:hint="Enter number 2"/>
<TextView
android:id="@+id/textViewResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextNumber2"
android:layout_marginTop="16dp"
android:text=""
android:textSize="18sp"/>
<Button
android:id="@+id/buttonAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textViewResult"
android:layout_marginTop="16dp"
13
android:text="Add"/>
<Button
android:id="@+id/buttonSubtract"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/buttonAdd"
android:layout_marginTop="8dp"
android:text="Subtract"/>
<Button
android:id="@+id/buttonMultiply"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/buttonSubtract"
android:layout_marginTop="8dp"
android:text="Multiply"/>
<Button
android:id="@+id/buttonDivide"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/buttonMultiply"
android:layout_marginTop="8dp"
android:text="Divide"/>
</RelativeLayout>
MainActivity.java File: -
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
14
editTextNumber1 = findViewById(R.id.editTextNumber1);
editTextNumber2 = findViewById(R.id.editTextNumber2);
textViewResult = findViewById(R.id.textViewResult);
double result = 0;
switch (operator) {
case '+':
15
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
} else {
textViewResult.setText("Cannot divide by zero");
return;
}
break;
}
OUTPUT: -
16
Task 7: Design an application based on WebView to
display an existing Website/Webpage
activity_main.xml: -
<?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">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
MainActivity.java File: -
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import androidx.appcompat.app.AppCompatActivity;
@Override
super.onCreate(savedInstanceState);
17
setContentView(R.layout.activity_main);
// Initialize WebView
webView = findViewById(R.id.webView);
webSettings.setJavaScriptEnabled(true);
// Load a website
webView.loadUrl(websiteUrl);
OUTPUT: -
18
Task 8: Design an application based on Auto Complete
Text View
activity_main.xml File: -
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="Type a country"
android:completionThreshold="1" />
<Button
android:id="@+id/buttonSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/autoCompleteTextView"
android:layout_marginTop="16dp"
android:text="Submit" />
</RelativeLayout>
MainActivity.java File: -
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
19
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autoCompleteTextView = findViewById(R.id.autoCompleteTextView);
buttonSubmit = findViewById(R.id.buttonSubmit);
20
OUTPUT: -
21
Task 9: Design an application for Linking of activities using Intent
Class and transfer your data from
MainActivity to another activity using Bundle Class.
Mainactivity.java :
package com.example.intent;
import androidx.appcompat.app.AppCompatActivity; import android.content.Intent;
import android.os.Bundle; import android.widget.Button;
import android.widget.EditText;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); send_button
= findViewById(R.id.send_button_id); send_text = findViewById(R.id.send_text_id);
send_text2 = findViewById(R.id.send_text_id2);
First_activity.java:
package com.example.intent;
import android.content.Intent; import android.os.Bundle; import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity; public class first_activity extends
AppCompatActivity {
TextView receiver_msg;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
receiver_msg = findViewById(R.id.received_value_id); Intent intent = getIntent();
String str1 = intent.getStringExtra("message_key1"); String str2 =
intent.getStringExtra("message_key2"); String concatenatedString = str1 + " wants to be a " + str2;
receiver_msg.setText(concatenatedString);
22
OUTPUT:
23
Task 10: Design an application for Database connectivity using SQLite
database. Create table stud_details and perform all possible queries of
insertion, deletion, updation on the click of buttons using SQLite in
Android Studio.
package com.example.database;
@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);
et1=findViewById(R.id.et1);
et2=findViewById(R.id.et2); et3=findViewById(R.id.et3); et4=findViewById(R.id.et4);
tv=findViewById(R. id.tv); b1.setOnClickListener(this);
b2. setOnClickListener(this); b3.setOnClickListener(this);
@SuppressLint("SetTextI18n") @Override
public void onClick(View v) { if (v == b1) {
//obj.execSQL("CREATE TABLE IF NOT EXISTS studentinfo(sid numeric PRIMARY KEY NOT
NULL, name CHAR,age numeric,phone number);");
et1.setText(" "); et2.setText(" ");
et3.setText(" "); et4.setText(" ");
}
if (v == b2) {
obj.execSQL("CREATE TABLE IF NOT EXISTS studentinfo(sid numeric PRIMARY KEY NOT
NULL, name CHAR,age numeric,phone number);");
sid = et1.getText().toString(); name = et2.getText().toString();
age = et3.getText().toString(); pn
= et4.getText().toString();
24
try {
abc = "INSERT INTO studentinfo VALUES('" + sid + "', '" + name + "','" + age + "', '" + pn +
"');";
obj.execSQL(abc); tv.setText("One record inserted");
} catch (Exception ex) {
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
if (v == b3) {
sid = et1.getText().toString();
try {
abc = "DELETE from studentinfo WHERE bid='" + sid + "'";
obj.execSQL(abc);
tv.setText("record deleted");
} catch (Exception ex) {
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
25
Task 11: Design a billing application using CheckBoxes in Android
Studio for a bookstore.
package com.example.training_options;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
c1=findViewById(R.id.checkBox); c2=findViewById(R.id.checkBox2);
c3=findViewById(R.id.checkBox3);
c4=findViewById(R.id.checkBox4);
c5=findViewById(R.id.checkBox5); t1=findViewById(R.id.textView3);
c1.setOnCheckedChangeListener(this);
c2.setOnCheckedChangeListener(this); c3.setOnCheckedChangeListener(this);
c4.setOnCheckedChangeListener(this); c5.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{ int bill=0; if(c1.isChecked())
{
bill+=150;
}
if(c2.isChecked())
{
bill+=500;
}
if(c3.isChecked())
{
bill+=150;
26
}
if(c4.isChecked())
{
bill+=200;
}
if(c5.isChecked())
{
bill+=50;
}
String a="Your Total Bill :"+ String.valueOf(bill); t1.setText(a);
}
}
27
Task 12: Working with CalendarView in Android Studio.
package com.example.calendarview; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color; import android.os.Bundle; import android.widget.CalendarView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
CalendarView calendar;
TextView dateView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
calendar = findViewById(R.id.calendarView);
dateView = findViewById(R.id.textView);
dateView.setTextColor(Color.RED);
calendar.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int
dayOfMonth)
{
String Date = dayOfMonth + "/" + (month + 1) + "/" +year; dateView.setText("Selected date "+Date);
}
});
}
}
28
Task 13: Design an application using Seek Bar in Android Studio.
package com.example.seek_bar;
super.onCreate(savedInstanceState); EdgeToEdge.enable(this);
setContentView(R.layout.activity_main); seekBar=(SeekBar)findViewById(R.id.seekBar);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { int
progressChangedValue = 0;
29