© Khmer Angkor Academy - sophearithput168

Project: Notes App (SQLite)

📒 Project: Notes App with SQLite Database

នៅក្នុងគម្រោងនេះ យើងនឹងបង្កើត Notes App មួយដែលប្រើ SQLite Database សម្រាប់រក្សាទុកកំណត់ត្រា។ គម្រោងនេះផ្តោតលើ CRUD Operations (Create, Read, Update, Delete) ជាមួយ SQLite!

📋 Features នៃ Notes App

Feature ពិពណ៌នា
Create Notes បង្កើតកំណត់ត្រាថ្មី ជាមួយ title និង content
📖 Read Notes អានកំណត់ត្រាទាំងអស់ពី database
✏️ Update Notes កែសម្រួលកំណត់ត្រា
🗑️ Delete Notes លុបកំណត់ត្រា
💾 SQLite Database រក្សាទុកទិន្នន័យជាអចិន្ត្រៃយ៍
🔍 Search Notes ស្វែងរកកំណត់ត្រា
🎨 Color Categories ពណ៌ផ្សេងៗសម្រាប់ប្រភេទ

📁 Project Structure

មុនពេលចាប់ផ្តើម សូមយល់ដឹងអំពីរចនាសម្ព័ន្ធ files នៃគម្រោង:

📦 NotesApp/
├── 📂 app/
│   ├── 📂 src/
│   │   ├── 📂 main/
│   │   │   ├── 📂 java/
│   │   │   │   └── 📂 com/example/notesapp/
│   │   │   │       ├── MainActivity.java
│   │   │   │       ├── AddNoteActivity.java
│   │   │   │       ├── Note.java
│   │   │   │       ├── NoteAdapter.java
│   │   │   │       └── DatabaseHelper.java
│   │   │   ├── 📂 res/
│   │   │   │   ├── 📂 layout/
│   │   │   │   │   ├── activity_main.xml
│   │   │   │   │   ├── activity_add_note.xml
│   │   │   │   │   └── item_note.xml
│   │   │   │   ├── 📂 values/
│   │   │   │   │   ├── colors.xml
│   │   │   │   │   └── strings.xml
│   │   │   │   └── 📂 drawable/
│   │   │   └── AndroidManifest.xml
│   └── build.gradle
└── build.gradle

📝 Note: បង្កើត New Project នៅក្នុង Android Studio ជាមួយ Empty Activity template។ បន្ទាប់មក right-click លើ package name ហើយជ្រើសរើស New → Java Class ដើម្បីបង្កើត Note.java, NoteAdapter.java, DatabaseHelper.java និង AddNoteActivity.java

🎨 Step 1: Note Model (Note.java)

បង្កើត model class សម្រាប់ Note object។

Java Code
Click "Run" to execute the Java code

💾 Step 2: Database Helper (DatabaseHelper.java)

បង្កើត SQLite database helper ជាមួយ CRUD operations ពេញលេញ។

Java Code
Click "Run" to execute the Java code

🎨 Step 3: Main Activity Layout (activity_main.xml)

បង្កើត layout សម្រាប់ main screen ជាមួយ RecyclerView និង FloatingActionButton។

Java Code
Click "Run" to execute the Java code

🎨 Step 4: Note Item Layout (item_note.xml)

បង្កើត layout សម្រាប់ note item នីមួយៗក្នុង RecyclerView។

Java Code
Click "Run" to execute the Java code

🎨 Step 5: Add Note Layout (activity_add_note.xml)

បង្កើត layout សម្រាប់ add/edit note screen។

Java Code
Click "Run" to execute the Java code

🔄 Step 6: Note Adapter (NoteAdapter.java)

បង្កើត RecyclerView adapter សម្រាប់បង្ហាញ notes។

Java Code
Click "Run" to execute the Java code

💻 Step 7: Add Note Activity (AddNoteActivity.java)

បង្កើត activity សម្រាប់បន្ថែម និងកែសម្រួល notes។

Java Code
Click "Run" to execute the Java code

💻 Step 8: Main Activity (MainActivity.java)

បង្កើត main activity ដែលបង្ហាញបញ្ជី notes។

Java Code
Click "Run" to execute the Java code

🎯 SQLite Database Concepts

1. Database Schema

Column Type Description
id INTEGER PRIMARY KEY Auto-increment unique ID
title TEXT NOT NULL ចំណងជើងកំណត់ត្រា
content TEXT មាតិកាកំណត់ត្រា
color TEXT ពណ៌នៃកំណត់ត្រា
timestamp INTEGER ពេលវេលាបង្កើត/កែសម្រួល

2. CRUD Operations

Operation SQL Method Java Method
Create INSERT INTO db.insert()
Read SELECT * FROM db.query()
Update UPDATE SET db.update()
Delete DELETE FROM db.delete()

✨ Advanced Features (Optional)

💡 អ្នកអាចបន្ថែមបាន:

  • 🔍 Full-text search functionality
  • 📌 Pin important notes to top
  • 🗂️ Categories/Folders for organization
  • 📷 Image attachments
  • 🔒 Password protection
  • 📤 Export notes to text files
  • ☁️ Cloud backup (Firebase)
  • 🎤 Voice notes
  • ✅ Checklist within notes

🐛 Common SQLite Issues & Solutions

Issue Solution
Database locked error Always close database in finally block
No such table error Check table name spelling, ensure onCreate() runs
Cursor not closed Use try-with-resources or close cursor manually
Data not updating Call notifyDataSetChanged() after database changes
App crashes on startup Check SQL syntax in CREATE TABLE statement

📱 Update AndroidManifest.xml

បន្ថែម AddNoteActivity នៅក្នុង AndroidManifest.xml:

<activity
    android:name=".AddNoteActivity"
    android:parentActivityName=".MainActivity"/>

🎓 Learning Outcomes

បន្ទាប់ពីបញ្ចប់គម្រោងនេះ អ្នកនឹងយល់ដឹងពី:

  • ✅ SQLite database design
  • ✅ SQLiteOpenHelper class
  • ✅ CRUD operations (Create, Read, Update, Delete)
  • ✅ ContentValues for inserting data
  • ✅ Cursor for reading data
  • ✅ Database versioning & migration
  • ✅ RecyclerView with database
  • ✅ Activity communication with Intent
  • ✅ Search functionality

✅ Congratulations! អ្នកបានបង្កើត Notes App មួយដែលប្រើ SQLite Database ពេញលេញ! នេះគឺជា foundation ល្អសម្រាប់ apps ដែលត្រូវការរក្សាទុកទិន្នន័យ locally!