Android SQLite Example and Interface Use

Hello there. In this article, I’ll reiterate the use of the database that some of the testers said they got errors, and I will also refer to the use of SQLite.

I’m skipping steps to create projects. The application will do exactly as follows. For a person to enter basic information such as model, name will be saved

Screen Design

Here we enter information for a person. As you click the Save button, these values will be added to the database.

Create a Database

Create a class called “Database” by right-clicking on the src folder and calling new-class. Edit your classroom as follows.

He underlined it because we did not import the package. Press ALT + ENTER, or add and say import by holding on to the cursor.

I’m telling these things for. If I give you the finished form of the class directly, do not waste time typing and understand how it is. Also, there are a lot of big and small letters here.

I will not tell you again what you are doing. But I will briefly mention it. You can learn what these mean from the previous database lessons. After filling in these fields, the view looks like this.


Here we briefly create a database named “persons”, a table named “persons”, and entered the table fields. Now that the database creation is over, let’s go to the actual code.

Matching Tools with Id Values

We will match the id values for the tools we have defined on the screen, such as button, TexView. Scroll down to the class and type the following code.

As you see, we performed the above set operations. There is no id for defining the onClick method for the Save button.

If something is underlined, you have to import it. You can add it by pressing ALT + ENTER.

Now let’s write what will be done when the button is clicked.

Save Button Codes

We created the click event using the onClick method. Let’s write the things that will happen when you click here. After writing, the final view of the codes looks like this:

Click on the button to enter the AddRecord () method.

Now fill in the AddRecord () method.

Now let’s run our practice and give it a try.


Displaying the Information in the Database with SQLite

Now we can see the values we added to the database with the SQLite program. I downloaded the Db Browser for SQlite program. Now we need to take our database to the desktop first. Do this for that.

Download it by clicking on the appropriate link at the site and perform the installation.

Run your app. So you work for the emulator. Not without this. Fully run and view your project. Later,

Do not forget the project will be open !!

  • Step 1 Click on the File Explorer tab
  • Step 2 From here, click on data> data> project name options from the right hand side to go to the folder where your database is located.
  • Step 3 Press button on the right  (pull a file from the device). Then save the database on your desktop.

Database Open

Let’s look at the program we downloaded.

  • Click Open Database

Select the database file we saved above and open it

Then, click on executeSQL. Let’s take a query to our database and see our result

Get Record

I’ll just take the name, you can get everything you want

First, we add the design TextView and Button

After doing this, we organize the MainActivity part like this

  • File:src/MainActivity.class



You can print it on the name screen by clicking on the Get button.

the function that performs the operation has already been shared “GetRecord()”


if you have question do not forget to write from the chat button next to it or from the comment


You may also like...

Leave a Reply

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