MAD Program
MAD Program
XML FILE:
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recipient Email" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Subject" />
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Message"
android:inputType="textMultiLine"
android:lines="4" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Email" />
</LinearLayout>
JAVA FILE:
package com.example.e_mail;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sendto = findViewById(R.id.editText1);
subject = findViewById(R.id.editText2);
body = findViewById(R.id.editText3);
button = findViewById(R.id.button);
button.setOnClickListener(view -> {
String emailsend = sendto.getText().toString();
String emailsubject = subject.getText().toString();
String emailbody = body.getText().toString();
XML FILE:
<TextView
android:id="@+id/t1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hobbies" />
<CheckBox
android:id="@+id/c1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Swimming" />
<CheckBox
android:id="@+id/c2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Running" />
<CheckBox
android:id="@+id/c3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cycling" />
<CheckBox
android:id="@+id/c4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reading" />
<CheckBox
android:id="@+id/c5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Football" />
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
JAVAFILE:
package com.example.checkbox;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.b1);
c1 = findViewById(R.id.c1);
c2 = findViewById(R.id.c2);
c3 = findViewById(R.id.c3);
c4 = findViewById(R.id.c4);
c5 = findViewById(R.id.c5);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int count = 0; // Initialize count
if (c1.isChecked()) count++;
if (c2.isChecked()) count++;
if (c3.isChecked()) count++;
if (c4.isChecked()) count++;
if (c5.isChecked()) count++;
XML FILE:
<?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:padding="10dp">
<TextView
android:id="@+id/sensorslist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Sensors" />
</LinearLayout>
JAVAFILE:
package com.example.sensor;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.List;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtList.setText(strBuilder.toString());
}
}
OR
24.write a program to demonstrate declaring and using permissions
with any relevant example.
XML FILE:
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CAMERA"
android:textSize="20sp"
android:gravity="center" />
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/text"
android:layout_marginTop="20dp"
android:contentDescription="Captured Image" />
<Button
android:id="@+id/photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="TAKE PHOTO" />
</RelativeLayout>
JAVAFILE:
package com.example.camera;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private Button b1;
private ImageView imageView;
private static final int CAMERA_REQUEST = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.photo);
imageView = findViewById(R.id.image);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_REQUEST);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK && data != null) {
Bitmap image = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(image);
}
}
}
MANIFEST FILE:
<uses-permission android:name="android.permission.CAMERA" />
5. Develop android application to enter one number and display
factorial of a number once click on button.
XML FILE:
<EditText
android:id="@+id/number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a number"
android:inputType="number" />
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/number"
android:text="Calculate Factorial" />
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btn1"
android:layout_marginTop="16dp" />
</RelativeLayout>
JAVAFILE:
package com.example.factorial;
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;
number = findViewById(R.id.number);
btn1 = findViewById(R.id.btn1);
tv = findViewById(R.id.tv);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String strnum = number.getText().toString(); // Get input from EditText
if (!strnum.isEmpty()) { // Check if input is not empty
int num = Integer.parseInt(strnum); // Parse input to integer
long factorial = calculateFactorial(num); // Calculate factorial
tv.setText("Factorial: " + factorial); // Display result
} else {
tv.setText("Please enter a number"); // Prompt user for input
}
}
});
}
XMLFILE:
<AutoCompleteTextView
android:id="@+id/txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Text to search" />
</RelativeLayout>
JAVA FILE:
package com.example.autotext;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt.setAdapter(adapter);
}
}
XML FILE:
<TextView
android:id="@+id/formTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Registration Form"
android:textSize="24sp"
android:layout_gravity="center"
android:layout_marginBottom="20dp"/>
<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Full Name"
android:inputType="textPersonName"
android:layout_marginBottom="16dp"/>
<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Email"
android:inputType="textEmailAddress"
android:layout_marginBottom="16dp"/>
<TextView
android:id="@+id/labelGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender:"
android:layout_marginBottom="8dp"/>
<RadioGroup
android:id="@+id/radioGroupGender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dp">
<RadioButton
android:id="@+id/rbMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:layout_marginEnd="16dp"/>
<RadioButton
android:id="@+id/rbFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:layout_marginEnd="16dp"/>
<RadioButton
android:id="@+id/rbOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Other"/>
</RadioGroup>
<TextView
android:id="@+id/labelCourse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Course:"
android:layout_marginBottom="8dp"/>
<Spinner
android:id="@+id/spinnerCourse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp" />
<Button
android:id="@+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
XMLFILE:
JAVAFILE:
package com.example.listview;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
• EditText
• Button
• ImageView
• ListView
• CheckBox
• RadioButton
• ProgressBar
XMLFILE:
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
</LinearLayout>
JAVAFILE:
package com.example.ui;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
XMLFILE:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bluetooth"
android:id="@+id/text"
android:textSize="20sp"
android:gravity="center"/>
<Button
android:id="@+id/on"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_marginTop="62dp"
android:text="ON" />
<Button
android:id="@+id/discoverable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/on"
android:layout_marginTop="74dp"
android:text="DISCOVERABLE" />
<Button
android:id="@+id/off"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/discoverable"
android:layout_marginTop="104dp"
android:text="OFF" />
</RelativeLayout>
JAVAFILE:
package com.example.bluetooth;
import androidx.appcompat.app.AppCompatActivity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Button on = findViewById(R.id.on);
Button discoverable = findViewById(R.id.discoverable);
Button off = findViewById(R.id.off);
on.setOnClickListener(v -> {
if (!bluetoothAdapter.isEnabled()) {
startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),1);
}
});
discoverable.setOnClickListener(v -> {
if (!bluetoothAdapter.isDiscovering()) {
startActivityForResult(new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE), 2);
}
});
XMLFILE:
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Marksheet"
android:textSize="24sp"
android:layout_gravity="center"
android:layout_marginBottom="20dp" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate"
android:layout_gravity="center" />
</LinearLayout>
JAVAFILE:
package com.example.studentmarksheet;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
subjects[0] = findViewById(R.id.subject1_marks);
subjects[1] = findViewById(R.id.subject2_marks);
subjects[2] = findViewById(R.id.subject3_marks);
subjects[3] = findViewById(R.id.subject4_marks);
subjects[4] = findViewById(R.id.subject5_marks);
totalMarks = findViewById(R.id.total_marks);
percentage = findViewById(R.id.percentage);
calculateButton = findViewById(R.id.submit_button);
calculateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int total = 0;
try {
for (EditText subject : subjects) {
total += Integer.parseInt(subject.getText().toString());
}
double percentageValue = (total / 500.0) * 100;
totalMarks.setText(String.valueOf(total));
percentage.setText(String.format("%.2f%%", percentageValue));
} catch (NumberFormatException e) {
Toast.makeText(MainActivity.this, "Please enter valid marks",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
12. Develop an application to store student details like roll no, name,
marks and retrieve student information using roll no. in SQLite
database. (Write java andxml file).
XML FILE:
<EditText
android:id="@+id/editRollNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Roll No"
android:inputType="number" />
<EditText
android:id="@+id/editName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:inputType="text" />
<EditText
android:id="@+id/editMarks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Marks"
android:inputType="number" />
<Button
android:id="@+id/saveButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save" />
<EditText
android:id="@+id/searchRollNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search Roll No"
android:inputType="number" />
<Button
android:id="@+id/searchButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search" />
<TextView
android:id="@+id/studentInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Student Info"
android:textSize="18sp"
android:gravity="center"
android:layout_marginTop="20dp" />
</LinearLayout>
JAVA FILE:
package com.example.sql;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editRollNo = findViewById(R.id.editRollNo);
editName = findViewById(R.id.editName);
editMarks = findViewById(R.id.editMarks);
searchRollNo = findViewById(R.id.searchRollNo);
studentInfo = findViewById(R.id.studentInfo);
Button saveButton = findViewById(R.id.saveButton);
Button searchButton = findViewById(R.id.searchButton);
saveButton.setOnClickListener(v -> {
String rollNo = editRollNo.getText().toString();
String name = editName.getText().toString();
String marks = editMarks.getText().toString();
if (!rollNo.isEmpty() && !name.isEmpty() && !marks.isEmpty()) {
ContentValues values = new ContentValues();
values.put("roll_no", rollNo);
values.put("name", name);
values.put("marks", marks);
long result = database.insert("students", null, values);
Toast.makeText(this, result == -1 ? "Failed to save" : "Saved",
Toast.LENGTH_SHORT).show();
clearFields();
} else {
Toast.makeText(this, "Fill all fields", Toast.LENGTH_SHORT).show();
}
});
searchButton.setOnClickListener(v -> {
String rollNo = searchRollNo.getText().toString();
if (!rollNo.isEmpty()) {
Cursor cursor = database.query("students", null, "roll_no = ?", new String[]{rollNo},
null, null, null);
if (cursor != null && cursor.moveToFirst()) {
String name = cursor.getString(cursor.getColumnIndex("name"));
String marks = cursor.getString(cursor.getColumnIndex("marks"));
studentInfo.setText("Roll No: " + rollNo + "\nName: " + name + "\nMarks: " +
marks);
cursor.close();
} else {
studentInfo.setText("Not found");
}
} else {
Toast.makeText(this, "Enter roll number", Toast.LENGTH_SHORT).show();
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
if (database != null) {
database.close();
}
}
}
XMLFILE:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="List View"
android:textSize="20sp"
android:layout_marginBottom="8dp" />
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Grid View"
android:textSize="20sp"
android:layout_marginBottom="8dp" />
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="4"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Image View"
android:textSize="20sp"
android:layout_marginBottom="8dp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@drawable/ic_launcher_background"/>
</LinearLayout>
JAVAFILE:
package com.example.list;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
ListView listView;
GridView gridView;
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.listView);
gridView = findViewById(R.id.gridView);
imageView = findViewById(R.id.imageView);
String[] listItems = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"};
ArrayAdapter<String> listAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, listItems);
listView.setAdapter(listAdapter);
String[] gridItems = new String[16];
for (int i = 0; i < 16; i++) {
gridItems[i] = "Grid " + (i + 1);
}
ArrayAdapter<String> gridAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, gridItems);
gridView.setAdapter(gridAdapter);
}
}
XML FILE:
<TextView
android:id="@+id/t1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0"
android:textSize="50sp"
android:padding="20dp"
android:gravity="end" />
<GridLayout
android:id="@+id/gridLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:columnCount="4"
android:rowCount="5">
JAVAFILE:
package com.example.calculator;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display = findViewById(R.id.t1);
GridLayout grid = findViewById(R.id.gridLayout);
XML FILE:
<TextView
android:id="@+id/formTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Employee Registration Form"
android:textSize="24sp"
android:layout_gravity="center"
android:layout_marginBottom="20dp"/>
<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Full Name"
android:inputType="textPersonName"
android:layout_marginBottom="16dp"/>
<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Email"
android:inputType="textEmailAddress"
android:layout_marginBottom="16dp"/>
<TextView
android:id="@+id/labelGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender:"
android:layout_marginBottom="8dp"/>
<RadioGroup
android:id="@+id/radioGroupGender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dp">
<RadioButton
android:id="@+id/rbMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:layout_marginEnd="16dp"/>
<RadioButton
android:id="@+id/rbFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:layout_marginEnd="16dp"/>
<RadioButton
android:id="@+id/rbOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Other"/>
</RadioGroup>
<TextView
android:id="@+id/labelDepartment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Department:"
android:layout_marginBottom="8dp"/>
<Spinner
android:id="@+id/spinnerDepartment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp" />
<Button
android:id="@+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
16. develope an android application for taking student feedback with
data base connectivity
XML FILE:
<TextView
android:id="@+id/formTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Feedback Form"
android:textSize="24sp"
android:layout_gravity="center"
android:layout_marginBottom="20dp"/>
<EditText
android:id="@+id/etStudentName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Your Name"
android:layout_marginBottom="16dp"/>
<EditText
android:id="@+id/etFeedback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Your Feedback"
android:inputType="textMultiLine"
android:layout_marginBottom="16dp"
android:minLines="3"
android:maxLines="5"/>
<Button
android:id="@+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit Feedback" />
</LinearLayout>
JAVAFILE:
package com.example.feedback;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
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);
etStudentName = findViewById(R.id.etStudentName);
etFeedback = findViewById(R.id.etFeedback);
Button btnSubmit = findViewById(R.id.btnSubmit);
if (name.isEmpty() || feedback.isEmpty()) {
Toast.makeText(this, "Please fill in all fields", Toast.LENGTH_SHORT).show();
return;
}
if (result != -1) {
Toast.makeText(this, "Feedback Submitted", Toast.LENGTH_SHORT).show();
etStudentName.setText("");
etFeedback.setText("");
} else {
Toast.makeText(this, "Error Submitting Feedback", Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (database != null) {
database.close();
}
}
}
17.Design an android application to show the list of paired
devices by Bluetooth
XML:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Paired Bluetooth Devices"
android:textSize="24sp"
android:layout_gravity="center"
android:layout_marginBottom="20dp"/>
<ListView
android:id="@+id/listViewDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
JAVAFILE:
package com.example.listblutooth;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Set;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listViewDevices = findViewById(R.id.listViewDevices);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
showPairedDevices();
}
private void showPairedDevices() {
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1);
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
adapter.add(device.getName() + "\n" + device.getAddress());
}
} else {
adapter.add("No paired devices found.");
}
listViewDevices.setAdapter(adapter);
}
}
MANIFESTFILE:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
JAVA FILE:
package com.example.hello;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new HelloWorldView(this));
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawText("Hello World", 10, 10, paint); // Draw "Hello World" at (10,
10)
}
}
}
19.Write an xml file to create login page using table layout.
XML FILE:
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:text="Username:"/>
<EditText
android:id="@+id/username"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter Username"/>
</TableRow>
<TableRow>
<TextView
android:text="Password:"/>
<EditText
android:id="@+id/password"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter Password"
android:inputType="textPassword"/>
</TableRow>
<TableRow>
<Button
android:id="@+id/login_button"
android:text="Login"/>
</TableRow>
</TableLayout>
</LinearLayout>
20.Develop an android application using radio button.
XML FILE:
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/apple"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apple" />
<RadioButton
android:id="@+id/banana"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Banana" />
<RadioButton
android:id="@+id/orange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Orange" />
</RadioGroup>
<Button
android:id="@+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textSize="18sp" />
</LinearLayout>
JAVAFILE:
package com.example.radiobutton;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
submitButton.setOnClickListener(v -> {
int selectedId = radioGroup.getCheckedRadioButtonId();
RadioButton selectedRadioButton = findViewById(selectedId);
resultTextView.setText(selectedRadioButton != null ?
selectedRadioButton.getText() : "None");
});
}
}
XML FILE:
<?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:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android Text to Speech (TTS) Demo"
android:textSize="24sp"
android:layout_gravity="center"
android:paddingBottom="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="thanks"
android:textSize="32sp"
android:layout_gravity="center"
android:paddingBottom="16dp"/>
<Button
android:id="@+id/speakButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CLICK TO CONVERT TEXT TO SPEECH"
android:layout_gravity="center"/>
</LinearLayout>
JAVA FILE:
package com.example.speech;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Locale;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
protected void onDestroy() {
if (textToSpeech != null) {
textToSpeech.shutdown();
}
super.onDestroy();
}
}
XML FILE
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="Bluetooth ON"
android:textOff="Bluetooth OFF" />
</LinearLayout>
JAVA FILE:
package com.example.bluetooth;
import android.bluetooth.BluetoothAdapter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.ToggleButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
toggleButton = findViewById(R.id.toggleButton);
if (bluetoothAdapter == null) {
showToast("Bluetooth not supported");
finish();
return;
}
toggleButton.setChecked(bluetoothAdapter.isEnabled());
toggleButton.setOnCheckedChangeListener(this::onToggleChanged);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
if (requestCode == REQUEST_BLUETOOTH_PERMISSION && grantResults.length
> 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
bluetoothAdapter.enable();
showToast("Bluetooth ON");
} else {
toggleButton.setChecked(false);
showToast("Permission denied");
}
}
Manifest file:
XML FILE
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Temperature Converter"
android:textSize="24sp"
android:paddingBottom="16dp" />
<EditText
android:id="@+id/inputTemperature"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter temperature"
android:inputType="numberDecimal"
android:padding="10dp" />
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="C to F"
android:textOff="F to C"
android:layout_marginTop="16dp" />
<Button
android:id="@+id/convertButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convert"
android:layout_marginTop="16dp" />
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:textSize="18sp" />
</LinearLayout>
JAVA FILE:
package com.example.tempretureconversion;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inputTemperature = findViewById(R.id.inputTemperature);
toggleButton = findViewById(R.id.toggleButton);
convertButton = findViewById(R.id.convertButton);
resultTextView = findViewById(R.id.resultTextView);
convertButton.setOnClickListener(this::convertTemperature);
}
XML FILE:
<?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:padding="20dp">
<EditText
android:id="@+id/num1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter first number"
android:inputType="numberDecimal"/>
<EditText
android:id="@+id/num2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter second number"
android:inputType="numberDecimal"/>
<Button
android:id="@+id/btnAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Addition"/>
<Button
android:id="@+id/btnSubtract"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subtraction"/>
<Button
android:id="@+id/btnMultiply"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Multiplication"/>
<Button
android:id="@+id/btnDivide"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Division"/>
<TextView
android:id="@+id/tvResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Result: "
android:textSize="18sp"
android:textStyle="bold"
android:padding="10dp"/>
</LinearLayout>
JAVA FILE:
package com.example.add;
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);
num1 = findViewById(R.id.num1);
num2 = findViewById(R.id.num2);
btnAdd = findViewById(R.id.btnAdd);
btnSubtract = findViewById(R.id.btnSubtract);
btnMultiply = findViewById(R.id.btnMultiply);
btnDivide = findViewById(R.id.btnDivide);
tvResult = findViewById(R.id.tvResult);
if (s1.isEmpty() || s2.isEmpty()) {
tvResult.setText("Please enter both numbers");
return;
}
switch (operator) {
case "+":
result = number1 + number2;
break;
case "-":
result = number1 - number2;
break;
case "*":
result = number1 * number2;
break;
case "/":
if (number2 == 0) {
tvResult.setText("Error: Cannot divide by zero");
return;
}
result = number1 / number2;
break;
}
XML FILE:
<Button
android:id="@+id/btnUpdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Toggle Employee Name" />
<TextView
android:id="@+id/txtResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:paddingTop="20dp"/>
</LinearLayout>
JAVA FILE:
package com.example.employee;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
SQLiteDatabase db;
TextView txtResult;
String empid = "E101";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtResult = findViewById(R.id.txtResult);
db = openOrCreateDatabase("EmployeeDB", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS Employee(empid TEXT PRIMARY
KEY, name TEXT)");
db.execSQL("INSERT OR IGNORE INTO Employee VALUES('E101', 'pqr')");
findViewById(R.id.btnUpdate).setOnClickListener(v ->
toggleEmployeeName());
displayUpdatedRecord();
}
private void toggleEmployeeName() {
Cursor c = db.rawQuery("SELECT name FROM Employee WHERE empid=?",
new String[]{empid});
if (c.moveToFirst()) {
String newName = c.getString(0).equals("pqr") ? "XYZ" : "pqr";
db.execSQL("UPDATE Employee SET name=? WHERE empid=?", new Object[]
{newName, empid});
}
c.close();
displayUpdatedRecord();
}