0% found this document useful (0 votes)
51 views1 page

Addnoteactivity - KT: Package Import Import Import Import Import Import Import Class Val Var Override Fun Super

This Kotlin code defines an AddNoteActivity class that extends AppCompatActivity. The activity allows adding or updating notes in a database table called "Notes". On create, it checks if an ID was passed in the intent extras to determine if it should populate the edit text fields and update button for an existing note versus adding a new note. The addFunc method inserts or updates the note details into the database table on button click by calling the insert method of a DbManager class, displaying a toast message on success or error.
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)
51 views1 page

Addnoteactivity - KT: Package Import Import Import Import Import Import Import Class Val Var Override Fun Super

This Kotlin code defines an AddNoteActivity class that extends AppCompatActivity. The activity allows adding or updating notes in a database table called "Notes". On create, it checks if an ID was passed in the intent extras to determine if it should populate the edit text fields and update button for an existing note versus adding a new note. The addFunc method inserts or updates the note details into the database table on button click by calling the insert method of a DbManager class, displaying a toast message on success or error.
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

AddNoteActivity.

kt
package [Link]

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

class AddNoteActivity : AppCompatActivity() {

val dbTable = "Notes"


var id = 0

override fun onCreate(savedInstanceState: Bundle?) {


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

try {
var bundle :Bundle = [Link]
id = [Link]("ID", 0)
if(id!=0){
//update note
//change actionbar title
supportActionBar!!.title = "Update Note"
//change button text
[Link] = "Update"
[Link]([Link]("name"))
[Link]([Link]("des"))
}

}catch (ex:Exception){}
}

fun addFunc(view: View) {


var dbManager = DbManager (this)

var values = ContentValues()


[Link]("Title", [Link]())
[Link]("Description", [Link]())

if (id == 0){
val ID = [Link](values)
if (ID>0){
[Link](this, "Note is added", Toast.LENGTH_SHORT).show()
}
else{
[Link](this, "Error adding note...", Toast.LENGTH_SHORT).show()
}
}

You might also like