0% found this document useful (0 votes)
8 views24 pages

Android Project Examples: UI & Logic

The document outlines the creation of multiple Android projects (exno2 to exno5) with specific functionalities. Each project includes a MainActivity with different UI components and layouts, such as buttons, text fields, and animations. The projects demonstrate various features like user input handling, calculations, animations, and a customized RatingBar.

Uploaded by

vigneshbvn2525
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views24 pages

Android Project Examples: UI & Logic

The document outlines the creation of multiple Android projects (exno2 to exno5) with specific functionalities. Each project includes a MainActivity with different UI components and layouts, such as buttons, text fields, and animations. The projects demonstrate various features like user input handling, calculations, animations, and a customized RatingBar.

Uploaded by

vigneshbvn2525
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Madlab

Exp 2:
Create project named exno2
[Link]

package [Link].exno2

import [Link]
import [Link]

class MainActivity : Activity() {


override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContentView([Link].activity_main) // Set the layout for the
activity
}
}

Then in res->create layout folder->and activity_main.xml


file
activity_main.xml

<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">

<!-- EditText -->


<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Edit Text" />

<!-- Button -->


<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

<!-- CheckBox -->


<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Checkbox" />

<!-- RadioButton -->


<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button" />

<!-- TextViews with different colors -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Green Color"
android:textColor="#00ff00" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red Color"
android:textColor="#ff0000" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blue Color"
android:textColor="#0000ff" />

<!-- TextViews with different font sizes -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Size 10"
android:textColor="#000000"
android:textSize="10dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Size 15"
android:textColor="#000000"
android:textSize="15dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Size 20"
android:textColor="#000000"
android:textSize="20dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Size 50"
android:textColor="#000000"
android:textSize="50dp" />
</LinearLayout>
Exp 3:
Create project named exno3
[Link]

package [Link].exno3

import [Link]
import [Link]
import [Link]
import [Link].*
import [Link]
import [Link].material3.*
import [Link].*
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity : ComponentActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContent {
CalculatorApp()
}
}
}

@Composable
fun CalculatorApp() {
var firstNumber by remember { mutableStateOf("") }
var secondNumber by remember { mutableStateOf("") }
var result by remember { mutableStateOf("") }

Column(
modifier = Modifier
.fillMaxSize()
.padding([Link]),
horizontalAlignment = [Link]
) {
Text(text = "Enter Number 1", fontSize = [Link])
OutlinedTextField(
value = firstNumber,
onValueChange = { firstNumber = it },
keyboardOptions = KeyboardOptions(keyboardType =
[Link]),
modifier = [Link]()
)

Spacer(modifier = [Link]([Link]))

Text(text = "Enter Number 2", fontSize = [Link])


OutlinedTextField(
value = secondNumber,
onValueChange = { secondNumber = it },
keyboardOptions = KeyboardOptions(keyboardType =
[Link]),
modifier = [Link]()
)

Spacer(modifier = [Link]([Link]))

Button(onClick = { result = calculate(firstNumber, secondNumber, "+")


}) {
Text(text = "Add")
}

Spacer(modifier = [Link]([Link]))

Button(onClick = { result = calculate(firstNumber, secondNumber, "-")


}) {
Text(text = "Subtract")
}

Spacer(modifier = [Link]([Link]))

Button(onClick = { result = calculate(firstNumber, secondNumber, "*")


}) {
Text(text = "Multiply")
}

Spacer(modifier = [Link]([Link]))

Text(text = "Result: $result", fontSize = [Link])


}
}

fun calculate(num1: String, num2: String, operation: String): String {


val a = [Link]()
val b = [Link]()

return if (a != null && b != null) {


when (operation) {
"+" -> "Sum = ${a + b}"
"-" -> "Sub = ${a - b}"
"*" -> "Mul = ${a * b}"
else -> "Invalid Operation"
}
} else {
"Enter valid numbers"
}
}
Then in res->create layout folder->and activity_main.xml
file
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Enter Number 1"
android:textSize="18sp" />

<EditText
android:id="@+id/first"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textView1"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="numberDecimal"
android:minHeight="48dp"
android:hint="Enter first number" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/first"
android:layout_marginTop="16dp"
android:layout_centerHorizontal="true"
android:text="Enter Number 2"
android:textSize="18sp" />

<EditText
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textView2"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="numberDecimal"
android:minHeight="48dp"
android:hint="Enter second number" />

<Button
android:id="@+id/buttonAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/second"
android:layout_marginTop="16dp"
android:text="Add" />

<Button
android:id="@+id/buttonSub"
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/buttonMul"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/buttonSub"
android:layout_marginTop="8dp"
android:text="Multiply" />

<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonMul"
android:layout_marginTop="16dp"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:text="Result will be displayed here" />

</RelativeLayout>

Exp 4:
Create project named exno4
[Link]

package [Link].exno4

import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity : AppCompatActivity() {

private lateinit var imageView: ImageView


private lateinit var blinkBTN: Button
private lateinit var rotateBTN: Button
private lateinit var fadeBTN: Button
private lateinit var moveBTN: Button
private lateinit var slideBTN: Button
private lateinit var zoomBTN: Button
private lateinit var stopBTN: Button

override fun onCreate(savedInstanceState: Bundle?) {


[Link](savedInstanceState)
setContentView([Link].activity_main)

// Initialize views
imageView = findViewById([Link])
blinkBTN = findViewById([Link])
rotateBTN = findViewById([Link])
fadeBTN = findViewById([Link])
moveBTN = findViewById([Link])
slideBTN = findViewById([Link])
zoomBTN = findViewById([Link])
stopBTN = findViewById([Link])

// Blink animation button click


[Link] {
val animation = [Link](this,
[Link].blink_animation)
[Link](animation)
}

// Rotate animation button click


[Link] {
val animation = [Link](this,
[Link].rotate_animation)
[Link](animation)
}

// Fade animation button click


[Link] {
val animation = [Link](this,
[Link].fade_animation)
[Link](animation)
}

// Move animation button click


[Link] {
val animation = [Link](this,
[Link].move_animation)
[Link](animation)
}

// Slide animation button click


[Link] {
val animation = [Link](this,
[Link].slide_animation)
[Link](animation)
}

// Zoom animation button click


[Link] {
val animation = [Link](this,
[Link].zoom_animation)
[Link](animation)
}

// Stop all animations


[Link] {
[Link]()
}
}
}

Then in res->create layout folder->and activity_main.xml


file
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ImageView
android:id="@+id/imageview"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_launcher_background" />

<LinearLayout
android:id="@+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/imageview"
android:layout_marginTop="30dp"
android:orientation="horizontal"
android:weightSum="3">

<Button
android:id="@+id/BTNblink"
style="@style/[Link]"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/blink"
android:textColor="@color/white" />

<Button
android:id="@+id/BTNrotate"
style="@style/[Link]"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/clockwise"
android:textColor="@color/white" />

<Button
android:id="@+id/BTNfade"
style="@style/[Link]"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/fade"
android:textColor="@color/white" />
</LinearLayout>

<LinearLayout
android:id="@+id/linear2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linear1"
android:layout_marginTop="30dp"
android:orientation="horizontal"
android:weightSum="3">

<Button
android:id="@+id/BTNmove"
style="@style/[Link]"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/move"
android:textColor="@color/white" />

<Button
android:id="@+id/BTNslide"
style="@style/[Link]"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/slide"
android:textColor="@color/white" />

<Button
android:id="@+id/BTNzoom"
style="@style/[Link]"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="3dp"
android:text="@string/zoom"
android:textColor="@color/white" />
</LinearLayout>

<Button
android:id="@+id/BTNstop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linear2"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:layout_marginRight="30dp"
android:text="@string/stop_animation" />
</RelativeLayout>

Exp 5:
Create project named exno5
[Link]

package [Link].exno5

import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity : AppCompatActivity() {


private lateinit var rt: RatingBar

override fun onCreate(savedInstanceState: Bundle?) {


[Link](savedInstanceState)
setContentView([Link].activity_main)
// Binding MainActivity with activity_main.xml
rt = findViewById([Link])

// Changing the color of RatingBar stars


val stars = [Link] as LayerDrawable
[Link](2).setColorFilter([Link],
[Link].SRC_ATOP)
}

fun Call(v: View) {


// Function called when button is clicked, displaying rating
val t = findViewById<TextView>([Link].textView2)
[Link] = "You Rated: ${[Link]}"
}
}

Then in res->create layout folder->and activity_main.xml


file
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="104dp"
android:background="@android:color/transparent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rate Me!!!"
android:textColor="@android:color/background_dark"
android:textSize="30sp"
android:textStyle="bold|italic"
tools:layout_editor_absoluteX="127dp"
tools:layout_editor_absoluteY="28dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColorHint="#FF0000"
android:textSize="24sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ratingBar" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:background="@android:color/holo_red_dark"
android:onClick="Call"
android:text="Submit"
android:textColor="@android:color/background_light"
android:textStyle="bold|italic"
app:layout_constraintTop_toBottomOf="@+id/ratingBar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />

</[Link]>

Exp 6:
Create project named exno6
[Link]

package [Link].exno6

import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContentView([Link].activity_main)

// Find WebView by ID
val webView: WebView = findViewById([Link])

// Enable debugging (for development only)


[Link](true)

// Configure WebView settings


[Link] {
javaScriptEnabled = true // Enable JavaScript
domStorageEnabled = true // Enable Local Storage
allowFileAccess = true
allowContentAccess = true
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
}

// Set WebViewClient to load in app


[Link] = WebViewClient()

// Set WebChromeClient for better performance


[Link] = object : WebChromeClient() {
override fun onReceivedTitle(view: WebView?, title: String?) {
[Link](view, title)
if (title == "A client-side exception has occurred") {
[Link](applicationContext, "Page failed to load!",
Toast.LENGTH_SHORT).show()
}
}
}

// Load the website


[Link]("[Link]
}
}

Then in res->create layout folder->and activity_main.xml


file
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<!-- WebView Component -->


<WebView
android:id="@+id/web"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

Exp 7:
[Link]

package [Link].exno7

import [Link]
import [Link]
import [Link]
import [Link].*
import [Link]
import [Link]
import [Link].material3.*
import [Link].*
import [Link]
import [Link]
import [Link]

@OptIn(ExperimentalMaterial3Api::class) // ✅ This removes the warning


class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContent {
MainScreen()
}
}
}

@OptIn(ExperimentalMaterial3Api::class) // ✅ Opt-in here too if needed


@Composable
fun MainScreen() {
var itemList by remember { mutableStateOf(listOf("Item 1", "Item 2", "Item
3")) }

Scaffold(
topBar = { SmallTopAppBar(title = { Text("RecyclerView Example") }) },
// ✅ Use SmallTopAppBar
floatingActionButton = {
FloatingActionButton(onClick = {
itemList = itemList + "Item ${[Link] + 1}"
}) {
Text("+")
}
}
) { paddingValues ->
Column(modifier = [Link](paddingValues)) {
LazyColumn(modifier = [Link]()) {
items(itemList) { item ->
ListItem(text = item)
}
}
}
}
}

@Composable
fun ListItem(text: String) {
Card(
modifier = Modifier
.fillMaxWidth()
.padding([Link]),
elevation = [Link](defaultElevation = [Link])
) {
Text(
text = text,
modifier = [Link]([Link])
)
}
}

@Preview(showBackground = true)
@Composable
fun PreviewMainScreen() {
MainScreen()
}

Then in res->create layout folder->and activity_main.xml


file

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</[Link]>

Exp 8:
[Link]

package [Link].exno8

import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity : AppCompatActivity() {

private val CHANNEL_ID = "channel_id_example" // Unique ID for the


channel

override fun onCreate(savedInstanceState: Bundle?) {


[Link](savedInstanceState)
setContentView([Link].activity_main)

createNotificationChannel() // ✅ Ensure the notification channel is


created

val button: Button = findViewById([Link])


[Link] {
showNotification()
}
}

@SuppressLint("MissingPermission")
private fun showNotification() {
val builder = [Link](this, CHANNEL_ID)
.setSmallIcon([Link].ic_launcher_background) // ✅ Ensure
'one' exists in res/drawable
.setContentTitle("Notification")
.setContentText("This is a notification")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)

with([Link](this)) {
notify(1, [Link]()) // ✅ Ensure unique ID (e.g., '1')
instead of '0'
}
}

private fun createNotificationChannel() {


if ([Link].SDK_INT >= Build.VERSION_CODES.O) {
val name = "Example Channel"
val descriptionText = "This is an example notification channel"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel(CHANNEL_ID, name,
importance).apply {
description = descriptionText
}

val notificationManager: NotificationManager =


getSystemService(Context.NOTIFICATION_SERVICE) as
NotificationManager
[Link](channel)
}
}
}

Then in res->create layout folder->and activity_main.xml


file

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Show Notification" />
</RelativeLayout>

Exp 9:
[Link]

package [Link].exno9

import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity : AppCompatActivity(), OnMapReadyCallback {


private lateinit var mMap: GoogleMap

override fun onCreate(savedInstanceState: Bundle?) {


[Link](savedInstanceState)
setContentView([Link].activity_main)

// Initialize the map fragment


val mapFragment = supportFragmentManager
.findFragmentById([Link]) as SupportMapFragment
[Link](this)
}

override fun onMapReady(googleMap: GoogleMap) {


mMap = googleMap

// Add a marker in Mayiladuthurai and move the camera


val mayiladuthurai = LatLng(11.1035, 79.6521)
[Link](MarkerOptions().position(mayiladuthurai).title("Marker
in Mayiladuthurai"))
[Link]([Link](mayiladuthurai,
12f))
}
}

Then in res->create layout folder->and activity_main.xml


file
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<fragment
android:id="@+id/map"
android:name="[Link]"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Exp 10:
[Link]

package [Link].exno10

import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link].*
import [Link]

class MainActivity : AppCompatActivity(), [Link] {


lateinit var rollNo: EditText
lateinit var name: EditText
lateinit var marks: EditText
lateinit var insert: Button
lateinit var delete: Button
lateinit var update: Button
lateinit var view: Button
lateinit var viewAll: Button
lateinit var dbHelper: DBHelper
lateinit var db: SQLiteDatabase

override fun onCreate(savedInstanceState: Bundle?) {


[Link](savedInstanceState)
setContentView([Link].activity_main)

// Initializing views
rollNo = findViewById([Link])
name = findViewById([Link])
marks = findViewById([Link])
insert = findViewById([Link])
delete = findViewById([Link])
update = findViewById([Link])
view = findViewById([Link])
viewAll = findViewById([Link])

// Setting listeners
[Link](this)
[Link](this)
[Link](this)
[Link](this)
[Link](this)

// Initialize database helper


dbHelper = DBHelper(this)
db = [Link]
}
override fun onClick(view: View?) {
when (view?.id) {
[Link] -> {
if ([Link]() || [Link]() ||
[Link]()) {
showMessage("Error", "Please enter all values")
return
}
[Link]("INSERT INTO student VALUES(?, ?, ?)",
arrayOf([Link](), [Link](), [Link]()))
showMessage("Success", "Record added")
clearText()
}

[Link] -> {
if ([Link]()) {
showMessage("Error", "Please enter Rollno")
return
}
val c: Cursor = [Link]("SELECT * FROM student WHERE
rollno=?", arrayOf([Link]()))
if ([Link]()) {
[Link]("DELETE FROM student WHERE rollno=?",
arrayOf([Link]()))
showMessage("Success", "Record Deleted")
} else {
showMessage("Error", "Invalid Rollno")
}
[Link]()
clearText()
}

[Link] -> {
if ([Link]()) {
showMessage("Error", "Please enter Rollno")
return
}
val c: Cursor = [Link]("SELECT * FROM student WHERE
rollno=?", arrayOf([Link]()))
if ([Link]()) {
[Link]("UPDATE student SET name=?, marks=? WHERE
rollno=?", arrayOf([Link](), [Link](),
[Link]()))
showMessage("Success", "Record Modified")
} else {
showMessage("Error", "Invalid Rollno")
}
[Link]()
clearText()
}

[Link] -> {
if ([Link]()) {
showMessage("Error", "Please enter Rollno")
return
}
val c: Cursor = [Link]("SELECT * FROM student WHERE
rollno=?", arrayOf([Link]()))
if ([Link]()) {
[Link]([Link](1))
[Link]([Link](2))
} else {
showMessage("Error", "Invalid Rollno")
clearText()
}
[Link]()
}

[Link] -> {
val c: Cursor = [Link]("SELECT * FROM student", null)
if ([Link] == 0) {
showMessage("Error", "No records found")
return
}
val buffer = StringBuffer()
while ([Link]()) {
[Link]("Rollno: ${[Link](0)}\n")
[Link]("Name: ${[Link](1)}\n")
[Link]("Marks: ${[Link](2)}\n\n")
}
showMessage("Student Details", [Link]())
[Link]()
}
}
}

private fun showMessage(title: String, message: String) {


val builder = [Link](this)
[Link](true)
[Link](title)
[Link](message)
[Link]()
}

private fun clearText() {


[Link]("")
[Link]("")
[Link]("")
[Link]()
}
}

Then in res->create layout folder->and activity_main.xml


file
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:orientation="vertical"
android:padding="20dp"
android:gravity="center_horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Details"
android:textSize="24sp"
android:textStyle="bold"
android:paddingBottom="10dp" />

<EditText
android:id="@+id/Rollno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:hint="Enter Roll Number"
android:inputType="number"
android:padding="10dp"
android:background="@android:drawable/editbox_background" />

<EditText
android:id="@+id/Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:hint="Enter Name"
android:inputType="text"
android:padding="10dp"
android:background="@android:drawable/editbox_background" />

<EditText
android:id="@+id/Marks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:hint="Enter Marks"
android:inputType="number"
android:padding="10dp"
android:background="@android:drawable/editbox_background" />

<Button
android:id="@+id/Insert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Insert"
android:minHeight="48dp"
android:backgroundTint="@color/teal_700" />

<Button
android:id="@+id/Delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Delete"
android:minHeight="48dp"
android:backgroundTint="@color/teal_700" />

<Button
android:id="@+id/Update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Update"
android:minHeight="48dp"
android:backgroundTint="@color/teal_700" />

<Button
android:id="@+id/View"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View"
android:minHeight="48dp"
android:backgroundTint="@color/teal_700" />

<Button
android:id="@+id/all"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View All"
android:minHeight="48dp"
android:backgroundTint="@color/teal_700" />

</LinearLayout>

You might also like