Crud Operations In SQLite in Android Studio Example

Hello, learners. Welcome to Crud Operations In SQLite in Android Studio example.

In Crud Operations In SQLite in Android tutorial, you will learn to insert, update/edit and delete records of SQLite database.

If you have not basic idea about SQLite, check SQLite In Android Example first.

If you want to do all crud operations with multiple table, then visit SQLite with multiple tables android

First, check the output of Crud Operations In SQLite in Android example, then we will develop it.

Download Source Code For crud operations in sqlite in android

[sociallocker] Download UpdateSQLite [/sociallocker]

Creating Crud Operations In SQLite in Android Studio Tutorial step by step

Step 1: Create a new project in Android Studio.

Step 2: Creating UserModel class

Create a new Java class named “UserModel” and add below source code

Step 3: Creating DatabaseHelper class

Create a new class named “DatabaseHelper” and all below source code

Step 4: Description of DatabaseHelper

Database name, Database version, table name and column names of tables are written as below.

Understanding most important part of SQLite Database

In onCreate() method, create statement for the table is written.

In onUpgrade() method, already exist tables are dropped and then all tables are recreated.

onCreate() method is called within onUpgrade() method to create tables.

In following scenarios, you need to upgrade DATABASE_VERSION number in increment order.

  1. When you add, update or delete any column of any table in the whole database.
  2. When you update any column name of any table.
  3. When you add, update or delete any table.
  4. When you update table name.

When DATABASE_VERSION is updated in increment order, onUpgrade() method is called.

addUserDetail() method will add the user to SQLite Database.

getAllUsers() method will fetch all the users from SQLite Database.

updateUser() method will update the user’s information.

deleteUser() method will delete the user from SQLite.

Step 5: Creating lv_item.xml file

Create a new layout resource file named “lv_item.xml” and add below

Step 6: Preparing CustomAdapter class

Make a new Java class named “CustomAdapter” and paste following

Step 7: Getting All Users From SQLite Database

Create a new activity named “GetAllUsersActivity“.

Copy and paste following source code in

Add below code in activity_get_all_users.xml

Step 8: Updating and deleting user information

Create a new activity named “UpdateDeleteActivity

Add below source code in

Copy following code in activity_update_delete.xml

Step 9: Preparing MainActivity

Add below code in

Copy following in activity_main.xml

So that is all for crud operations in SQLite in Android example.

Feel free to comment your queries and reviews in the comment section. Thank you.

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

7 Responses

  1. Dilly says:

    Good tutorial. I need assistance i have a app im developing and its called Speed dial. I cnt get the selected contacts to be saved on a buttons so ican speed dial.

  2. Andrea says:

    App is not working if opened from another activity. What should I do?

  3. jorrel says:

    hi having problems with the tutorial as there are some syntax errors “etname” when i assume they are suppose to be either set or get. any chance you can clarify. (urgent)

  4. Rodrigo says:

    Your tutorial helps me a lot! A perfect CRUD example. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *