Hey, Developers! In last tutorial we learned about the basic operation of CRUD in the SQLite Database using SQLiteOpenHelper class.
Now in this tutorial we're going to create a simple Notes App with SQLite as database storage. The app will be very minimal and will have only one screen to handle the notes.
At first, we will create android application. Then, we will see how to build Notes App in the application.
Follow steps below to create new project. Please ignore the steps if you have already created a new application.
S. No. | Steps |
1 | Open Android Studio. |
2 | Click on Start a new Android Studio Project then choose your project and select Empty Activity. |
3 | Write application name as NotesApp after this write a package name you can write your own package name. |
4 | Select language Java. Select minimum SDK you need. However, we have selected 17 as minimum SDK. Then, click next button. |
5 | If you have followed above process correctly, you will get a newly created project successfully. However, you can also visit tutorial to Create a New Project to know steps in detail. |
Open build.gradle under the folder of the app and add RecyclerView dependency.
" implementation 'com.android.support:recyclerview-v7:28.0.0' "
The RecyclerView will be used to show the notes in a list format.
Click on res => values folder and open the color.xml file. And include the following code.
Click on res => values folder and open the dimens.xml file. And include the following code.
Click on res => values folder and open strings.xml file. And include the following code. This file includes all the strings that the project uses.
We need to build a class extending from SQLiteOpenHelper. This class performs CRUD activities (Create, Read, Update, and Delete) on the database.
In order to handle notes readily, we also need a model class to generate Note items.
Click on java => com.ukacademe.notesapp and create a package and write a name as model under this package create a class named Note.java. In this class we define the SQLite table name, column names and create table SQL query along with getter / setter methods.
So open the Note.java class. And include the following code.
Right click on model => DatabaseHelper create a class called DatabaseHelper.java under the model package and extend the SQLiteOpenHelper class. This class holds methods for performing CRUD operations related to the database.
We use cookies to ensure you get the best experience on our website, if you continue to browse you'll be acconsent with our Cookies Policy.
Got it!