SQLite is Android's version of SQL. SQL - Structured Query Language - is a commonly used query langauge to store,access and edit data dynamically. SQLite is basically an entire SQL defined using Classes and methods defined in Android SDK. Developers can make use of these classes and methods to perform query functions on the data stored in their apps. In this app, we will be making two buttons - one for adding text records and another for views those text records. these twxt records are getting stroed in a database handled through SQLite.
Steps to develop this can be summarized below -
Now, let’s begin the development...
When the user clicks on Submit button, inesert_mybooks(View v) gets called which then calls dbh.insert_mybooks() method. This method is present in DB Helper class(mentioned later) which finally saves the entries in the database.
a) Inside DBHelper.class we create a constructor for creating instances of the database
b) OnCreate method ensures that whenever the database is prepared it saves a few initial values in it which can be used to display. We have entered 3 values here which user can view when they launch the app.
c) All the statements used in SQLite are same as SQL. You just need to know the right method and class to execute those statements. Like in this case, you can see that we are using execSQL() method which contains same SQL statements that you would use in SQL queries otherwise.
d)Here we have also defined insert_mybooks(String title, String author, String st) method that finally saves the data in database. ContentValues is a class that helps us to submit data in one go inside the database.
e) We use getReadableDatabase() and getWritableDatabse() to read and write data respectively.
f) There is another method listRecord() which provides a cursor object that can traverse through the database.
a)In the above activity, we initiate a cursor object during onStart() and move the cursor to the first position in the records.
b) Based upon what button user clicks on - previous/next - Cursor movements are decided.