Building a Notes App with SQLite

Jul 31, 2024

Notes App with SQLite Database

Overview

  • This series focuses on creating a fully functional Notes app using SQLite.
  • Topics covered include Create, Read, Update, and Delete (CRUD) operations.
  • Comparison with Firebase real-time database explained.

Functionality Preview

  • Display all notes in the main view.
  • Add new note using a Floating Action Button.
  • Options to edit and delete notes.
  • Local storage using SQLite, no need for online database.

Prerequisites

  • Room database will also be covered in future videos.
  • Ensure to subscribe for more updates.

Project Setup

  1. Create New Project:

    • Choose "Empty Activity"
    • Name: NotesSQLite
  2. Theme Customization:

    • Modify colors.xml to add orange color:
      <color name="Orange">#FF8C00</color>
      
    • Update themes.xml accordingly.
  3. Enable View Binding:

    • In build.gradle (Module):
      android {
        viewBinding {
          enabled = true
        }
      }
      
  4. Design Layouts:

    • Use recyclerView for displaying notes.
    • Create activity_main.xml with a Floating Action Button to add notes.

Adding Notes

  1. Design Add Note Activity Layout (activity_add_note.xml):

    • Include TextViews for title and content, and a save button.
  2. Coding Logic for Adding Notes:

    • Create a Node data class with fields: ID, title, content.
    • Implement SQLite database helper class for handling database operations.
    • Use CRUD operations to insert notes into the database.
  3. Testing Saving Functionality:

    • Once saved, user is redirected to main activity with a toast message.

Displaying Notes

  • Create a RecyclerView in activity_main.xml to display stored notes.
  • Implement an adapter to bind data to the RecyclerView.
  • Use SQL queries in the database helper to retrieve notes.
  • Display data using onResume() for real-time updates.

Updating Notes

  1. Create Update Activity Layout (activity_update_note.xml):

    • Similar to Add Note Activity but with different context.
  2. Implement Update Logic:

    • Pass the note ID to identify which note to edit.
    • Fetch current note data to pre-fill the fields.
    • Update note in the database on clicking the update button.

Deleting Notes

  1. Add Delete Functionality:

    • Create a delete button in each note item layout.
    • Implement delete logic in the adapter, using the database helper to remove the note.
  2. Testing Delete Functionality:

    • Verify deletion works by refreshing the displayed list after an item is deleted.

Conclusion

  • Completed a functional Notes app using SQLite.
  • Future topics will cover Room database and more advanced Android features.
  • Stay tuned for upcoming videos for more hands-on coding sessions!