I have a notes app I am creating. I created 2 activities and have button that on click should save notes and navigate to MainActivity and display notes.
binding.btnSaveNotes.setOnClickListener {
Toast.makeText(this@AddNotes, "Check Mark Clicked", Toast.LENGTH_SHORT).show()
val title = binding.editTextTitle.text.toString()
val noteDesc = binding.editTextDesc.text.toString()
if (title.isNotEmpty() || noteDesc.isNotEmpty()) {
val formatter = SimpleDateFormat("EEE, d MMM yyy HH:mm a")
note = if (isUpdate) {
Note(old_note.id, title, noteDesc, formatter.format(Date()))
} else {
Note(null, title, noteDesc, formatter.format(Date()))
}
val intent = Intent()
intent.putExtra("note", note)
setResult(Activity.RESULT_OK, intent)
finish()
} else {
Toast.makeText(this@AddNotes, "Please enter some data", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}
}
I have tried updating notes app to have button/floating action button or image image. Added back arrow as well. It does not seem to go inside this code post button click.
The code you uploaded is not enough, so I will make the related code I practiced before similar to your question.
Create the MainActivity layout (activity_main.xml) with a button to navigate to the AddNotes activity:
Create the MainActivity class (MainActivity.kt):
Create the AddNotes layout (activity_add_notes.xml) with an EditText for title, an EditText for description, and a button to save the note:
Create the AddNotes class (AddNotes.kt):
Create a data class Note to hold your note information:
I tested it and this code will work... Good luck.