1.
Develop a simple Button Click event and a calculator app utilizing event layouts and managers in
Android Studio.
SIMPLE BUTTON CLICK EVENT
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<Button
android:id="@+id/btnClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"/>
</LinearLayout>
[Link]
package [Link].ex1a;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
btn = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link], "Button Clicked!",
Toast.LENGTH_SHORT).show();
}
});
}
}
2. SIMPLE CALCULATOR APP
activity_main.xml
<LinearLayout xmlns:android="[Link]
android:orientation="vertical">
<TextView
android:id="@+id/t"
android:text="0"
android:textSize="30sp"/>
<GridLayout
android:columnCount="4">
<Button android:text="7" android:onClick="p"/>
<Button android:text="8" android:onClick="p"/>
<Button android:text="9" android:onClick="p"/>
<Button android:text="/" android:onClick="p"/>
<Button android:text="4" android:onClick="p"/>
<Button android:text="5" android:onClick="p"/>
<Button android:text="6" android:onClick="p"/>
<Button android:text="*" android:onClick="p"/>
<Button android:text="1" android:onClick="p"/>
<Button android:text="2" android:onClick="p"/>
<Button android:text="3" android:onClick="p"/>
<Button android:text="-" android:onClick="p"/>
<Button android:text="0" android:onClick="p"/>
<Button android:text="C" android:onClick="p"/>
<Button android:text="=" android:onClick="p"/>
<Button android:text="+" android:onClick="p"/>
</GridLayout>
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
public class MainActivity extends AppCompatActivity {
TextView t;
double a = 0;
String op = "";
protected void onCreate(Bundle b){
[Link](b);
setContentView([Link].activity_main);
t = findViewById([Link].t);
}
public void p(View v){
String x = ((Button)v).getText().toString();
String cur = [Link]().toString();
if([Link]("[0-9]")){
[Link]([Link]("0") ? x : cur + x);
}
else if([Link]("[+\\-*/]")){
a = [Link](cur);
op = x;
[Link]("0");
}
else if([Link]("=")){
double b = [Link](cur);
double r = 0;
if([Link]("+")) r = a + b;
else if([Link]("-")) r = a - b;
else if([Link]("*")) r = a * b;
else if([Link]("/")) r = (b != 0) ? a / b : 0;
[Link](""+r);
}
else if([Link]("C")){
[Link]("0");
a = 0; op = "";
}
}
}
[Link] storage app to demonstrate SQLite in Android Studio.
[Link]
package [Link].ex2;
import [Link].*;
import [Link];
import [Link].*;
public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "StudentDB", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
[Link]("CREATE TABLE students(id INTEGER PRIMARY KEY, name TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
[Link]("DROP TABLE IF EXISTS students");
onCreate(db);
}
// Insert
public void insert(String name) {
SQLiteDatabase db = [Link]();
[Link]("INSERT INTO students(name) VALUES('" + name + "')");
}
// View
public Cursor view() {
SQLiteDatabase db = [Link]();
return [Link]("SELECT * FROM students", null);
}
}
activity_main.xml
<LinearLayout
xmlns:android="[Link]
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/name"
android:hint="Enter Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:text="Insert"
android:onClick="insertData"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:text="View"
android:onClick="viewData"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
[Link]
package [Link].ex2;
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
public class MainActivity extends AppCompatActivity {
EditText name;
DBHelper db;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
name = findViewById([Link]);
db = new DBHelper(this);
}
public void insertData(View v) {
String n = [Link]().toString();
[Link](n);
[Link](this, "Inserted", Toast.LENGTH_SHORT).show();
}
public void viewData(View v) {
Cursor c = [Link]();
String data = "";
while ([Link]()) {
data += [Link](0) + " - " + [Link](1) + "\n";
}
[Link](this, data, Toast.LENGTH_LONG).show();
}
}
[Link] programs using Java to create Android application having Databases
● For a simple library application.
● For displaying books available, books lend, book reservation. Assume that student information is
available in a database which has been stored in a database server.
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "[Link]", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
[Link]("CREATE TABLE books(name TEXT, status TEXT, student TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
activity_main.xml
<LinearLayout xmlns:android="[Link]
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Book Name -->
<EditText
android:id="@+id/book"
android:hint="Book Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- Student ID -->
<EditText
android:id="@+id/student"
android:hint="Student ID"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- Buttons -->
<Button
android:id="@+id/add"
android:text="Add Book"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/view"
android:text="View Books"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/lend"
android:text="Lend Book"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/reserve"
android:text="Reserve Book"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- Result Display -->
<TextView
android:id="@+id/result"
android:text="Library Data"
android:textSize="18sp"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
public class MainActivity extends AppCompatActivity {
EditText book, student;
TextView result;
DB db;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
book = findViewById([Link]);
student = findViewById([Link]);
result = findViewById([Link]);
db = new DB(this);
findViewById([Link]).setOnClickListener(v -> addBook());
findViewById([Link]).setOnClickListener(v -> updateStatus("Lent"));
findViewById([Link]).setOnClickListener(v ->
updateStatus("Reserved"));
findViewById([Link]).setOnClickListener(v -> viewBooks());
}
// ADD BOOK
void addBook() {
SQLiteDatabase d = [Link]();
String b = [Link]().toString();
[Link]("INSERT INTO books VALUES('" + b + "','Available','-')");
[Link](this, "Book Added", Toast.LENGTH_SHORT).show();
}
// LEND / RESERVE (COMMON METHOD)
void updateStatus(String status) {
SQLiteDatabase d = [Link]();
String b = [Link]().toString();
String s = [Link]().toString();
[Link]("UPDATE books SET status='" + status + "', student='" + s +
"' WHERE name='" + b + "'");
[Link](this, status, Toast.LENGTH_SHORT).show();
}
// VIEW BOOKS
void viewBooks() {
SQLiteDatabase d = [Link]();
Cursor c = [Link]("SELECT * FROM books", null);
String data = "";
while ([Link]()) {
data += "Book: " + [Link](0) +
"\nStatus: " + [Link](1) +
"\nStudent: " + [Link](2) + "\n\n";
}
[Link](data);
}
}
4. Design an android application using Cordova for a user login screen with username,password, reset
button and a submit button. Also, include header image and a label. Use layout managers.
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Login App</title>
</head>
<body align="center">
<img src="[Link]
width="120"><br><br>
<label><b>User Login</b></label><br><br>
<form>
Username:<br>
<input type="text" id="u"><br><br>
Password:<br>
<input type="password" id="p"><br><br>
<input type="button" value="Submit" onclick="check()">
<input type="reset" value="Reset">
</form>
<p id="msg"></p>
<script>
function check()
{var a=[Link]("u").value;
var b=[Link]("p").value;
if(a=="admin" && b=="123")
[Link]("msg").innerHTML="Login Successful";
else
[Link]("msg").innerHTML="Invalid Login";}
</script>
</body>
</html>
[Link]
package [Link].ex4;
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle b) {
[Link](b);
WebView web = new WebView(this);
setContentView(web);
[Link]().setJavaScriptEnabled(true);
[Link](new WebViewClient());
[Link]("[Link]
}
}
📌 2. Folder Structure (IMPORTANT FOR CORDOVA)
app
└── src
└── main
├── java
├── res
└── assets
└── [Link]
5. Design and develop an android application using Apache Cordova to find and display the current
location of the user,also print the nearby hospitals,ATMs and restaurants using using a public Places
API(OpenStreetMap, Foursquare Places API)
1. INSTALL PLUGIN
cordova plugin add cordova-plugin-geolocation
2. [Link]
<!DOCTYPE html>
<html>
<head>
<title>Location App</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { text-align: center; font-family: Arial; }
button { padding: 10px; margin: 10px; }
</style>
</head>
<body>
<h2>My Location App</h2>
<button onclick="getLocation()">Get Location</button>
<p id="loc"></p>
<p id="result"></p>
<script>
function getLocation() {
[Link](showPosition);
}
function showPosition(position) {
var lat = [Link];
var lon = [Link];
[Link]("loc").innerHTML =
"Latitude: " + lat + "<br>Longitude: " + lon;
findPlaces(lat, lon);
}
function findPlaces(lat, lon) {
var query = `
[out:json];
(
node["amenity"="hospital"](around:1000, ${lat}, ${lon});
node["amenity"="atm"](around:1000, ${lat}, ${lon});
node["amenity"="restaurant"](around:1000, ${lat}, ${lon});
);
out;
`;
var url = "[Link] + encodeURIComponent(query);
fetch(url)
.then(response => [Link]())
.then(data => {
let output = "";
[Link](place => {
output += [Link] + " (" + [Link] + ")<br>";
});
[Link]("result").innerHTML = output;
});
}
</script>
</body>
</html>
3. Folder Structure
www/
└── [Link]
4. Run Commands
cordova create LocationApp
cd LocationApp
cordova platform add android
👉 Replace [Link]
cordova run android
6. Design and develop a simple notes making app/Recipe Book App using ionic utilizing the native
plugins suitable for Android/ios platforms.
Commands:
1. Check Node & npm
node -v
npm -v
2. Install Dependencies
npm install
3. Install Ionic CLI (if not installed)
npm install -g @ionic/cli
4. Create App
ionic start App blank
Select
● Angular
● Standalone
5. Go to Project Folder
cd App
6. Open Project
code .
7. Run Application
ionic serve
MODIFY FILES
Go to:
src/app/home/
Edit:
● [Link]
8. Run Again
ionic serve
OPTIONAL (ANDROID)
ionic build
npx cap add android
npx cap open android
—-------------------
[Link]
<ion-header>
<ion-toolbar>
<ion-title>Simple App</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
<ion-input [(ngModel)]="t" placeholder="Title"></ion-input>
<ion-textarea [(ngModel)]="d" placeholder="Description"></ion-textarea>
<ion-button (click)="add()">Add</ion-button>
<ion-item *ngFor="let i of list; let x = index">
{{ [Link] }} - {{ [Link] }}
<ion-button (click)="del(x)">X</ion-button>
</ion-item>
</ion-content>
[Link]
import { Component } from '@angular/core';
import { IonicModule } from '@ionic/angular';
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-home',
templateUrl: '[Link]',
standalone: true,
imports: [IonicModule, FormsModule, CommonModule]})
export class HomePage {
t = ''; d = '';
list: any[] = [];
add() {
if (this.t && this.d)
[Link]({ title: this.t, desc: this.d }),
this.t = this.d = ''; }
del(i: number) {
[Link](i, 1); }}
REACT NATIVE:
Commands:
1. Check [Link] Installation
node -v
npm -v
2. Install Expo CLI
npm install -g expo-cli
3. Create New Project
npx create-expo-app MyApp
4. Go to Project Folder
cd MyApp
5. Open Project in VS Code
code .
6. Start the App
npm start
Final Step
After the project runs:
Open and replace the code in app/(tabs)/[Link] (or [Link]) with your BMI / To-Do code.
[Link] react native, build a cross platform application for a BMI calculator.
import {useState} from 'react';
import {View,Text,TextInput,Button} from 'react-native';
export default function App(){
const[h,sH]=useState(''),[w,sW]=useState(''),[r,sR]=useState('');
const c=()=>{
let b=w/((h/100)*(h/100));
let t=b<18.5?'Underweight':b<25?'Normal':b<30?'Overweight':'Obese';
sR([Link](2)+' - '+t);
};
return(
<View>
<Text>BMI</Text>
<TextInput placeholder="Height" onChangeText={sH}/>
<TextInput placeholder="Weight" onChangeText={sW}/>
<Button title="Go" onPress={c}/>
<Text>{r}</Text>
</View>
);
}
[Link] a cross platform application for a simple expense manager which allows entering expenses
and income on each day and displays category wise weekly income and expenses.
import {useState} from 'react';
import {View,Text,TextInput,Button} from 'react-native';
export default function App(){
const[a,sA]=useState(''),[c,sC]=useState(''),[r,sR]=useState({});
const add=(t)=>{
if(!a||!c)return;
let x={...r};
if(!x[c]) x[c]={i:0,e:0};
x[c][t]+=+a;
sR(x);
};
return(
<View>
<Text>Expense</Text>
<TextInput placeholder="Amount" onChangeText={sA}/>
<TextInput placeholder="Category" onChangeText={sC}/>
<Button title="Income" onPress={()=>add('i')}/>
<Button title="Expense" onPress={()=>add('e')}/>
{[Link](r).map(k=>
<Text key={k}>{k} → I:{r[k].i} E:{r[k].e}</Text>
)}
</View>
);
}
[Link] a cross platform application to convert units from imperial system to metric system( km
to miles, kg to pounds etc.,)
import {useState} from 'react';
import {View,Text,TextInput,Button} from 'react-native';
export default function App(){
const[v,sV]=useState(''),[r,sR]=useState('');
return(
<View>
<Text>Converter</Text>
<TextInput placeholder="Value" onChangeText={sV}/>
<Button title="KM→Miles" onPress={()=>sR((v*0.62).toFixed(2)+' miles')}/>
<Button title="Miles→KM" onPress={()=>sR((v*1.61).toFixed(2)+' km')}/>
<Button title="KG→Pounds" onPress={()=>sR((v*2.2).toFixed(2)+' lb')}/>
<Button title="Pounds→KG" onPress={()=>sR((v/2.2).toFixed(2)+' kg')}/>
<Text>{r}</Text>
</View>
);
}
[Link] and develop a cross platform application for day to day task (to-do) management.
import {useState} from 'react';
import {View,Text,TextInput,Button,FlatList} from 'react-native';
export default function App(){
const[t,sT]=useState(''),[l,sL]=useState([]);
return(
<View>
<Text>ToDo</Text>
<TextInput onChangeText={sT}/>
<Button title="Add" onPress={()=>sL([...l,{id:[Link]()+'',t}])}/>
<FlatList data={l} renderItem={({item})=>
<Text onPress={()=>sL([Link](i=>[Link]!=[Link]))}>{item.t}</Text>
}/>
</View>
);
}
FLUTTER
Commands
1. Check Flutter Installation
flutter --version
2. Create New Project
flutter create currency_app
3. Go to Project Folder
cd currency_app
4. Open in VS Code
code .
5. Add HTTP Package (for API)
flutter pub add http
6. Run the App
flutter run
Final Step
After project runs:
👉 Open and replace code in
lib/[Link]
12. Develop a cross platform application using Flutter to convert currency using live exchange rates
from [Link]
import 'package:flutter/[Link]';
import 'package:http/[Link]' as http;
import 'dart:convert';
void main()=>runApp(MaterialApp(home:A()));
class A extends StatefulWidget{
@override State<A> createState()=>_A();
}
class _A extends State<A>{
String a="",r="";
g()async{
var d=jsonDecode((await
[Link]([Link]("[Link]
Ke76DOK56hLDWQAC14Y&base_currency=USD"))).body);
setState(()=>r=([Link](a)*d["data"]["INR"]).toString());
}
@override Widget build(c)=>Scaffold(
appBar:AppBar(title:Text("C")),
body:Column(children:[
TextField(onChanged:(v)=>a=v),
ElevatedButton(onPressed:g, child:Text("Go")),
Text(r)
])
);
}
⚠️ IMPORTANT STEP
👉[Link]
Get API key from:
👉 Replace:
YOUR_API_KEY - api key
13. Design and develop a kotlin application for day to day task (to-do) management.
1. activity_main.xml (SIMPLE UI)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/taskInput"
android:hint="Enter Task"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/addBtn"
android:text="Add Task"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
2. [Link] (VERY EASY CODE)
package [Link]
import [Link]
import [Link].*
import [Link]
class MainActivity : AppCompatActivity() {
lateinit var input: EditText
lateinit var listView: ListView
lateinit var adapter: ArrayAdapter<String>
var tasks = ArrayList<String>()
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContentView([Link].activity_main)
input = findViewById([Link])
listView = findViewById([Link])
adapter = ArrayAdapter(this, [Link].simple_list_item_1, tasks)
[Link] = adapter
findViewById<Button>([Link]).setOnClickListener {
val task = [Link]()
if (task != "") {
[Link](task)
[Link]()
[Link]("")
}
}
// Delete on click
[Link] { _, _, position, _ ->
[Link](position)
[Link]()
}
}
}