Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

LEARNING TASK 10

Legaspi, Mark Anthony BSIT-3A


Reminder. Read Module 10: Android SQLite Database first, before answering this section.

Instruction: Answer the following questions briefly, your


answer will be evaluated using the following rubric.

Holistic Rubric
Exceeding Meeting Approaching Below None
(10) (8) (6) (2) (0)
Substantial,
Content Clarity
specific, and/or
The presence of ideas Sufficient
illustrative
developed through developed Limited content Superficial
content No content
facts, examples, content with with inadequate and/or
demonstrating or answer
illustrations, details, adequate elaboration or minimal
strong provided.
opinions, statistics, elaboration or explanation content
development and
reasons, and/or explanation.
sophisticated
explanations.
ideas.

1. Use your application for Learning Task 9 (Lab), explain what are the files you
included in your app that are related to the proper usage of SQLite in order
to access and process information.

The files in my app that are related to the proper usage of SQLite are the
SqliteDatabase.Java and Contacts.java. The SqliteDatabase.java contains
methods to manipulate data in the database such as addContacts,
updateContacts, findContacts and deleteContacts. The SqliteDatabase.java
also contains the creation of the database, table and column. It creates an
object for creating, opening and managing the database and it specifies the
error handler. We can also update database version on this file. The
SqliteDatabase.Java contain some method which are onCreate(),
onUpgrade() and onDowngrade(). The onCreate() is called only once when
database is created for the first time. The onUpgrade is called when database
needs to be upgraded. And the onDowngrade is called when database needs
to be downgraded. Another file is the Contact.java and it is the model class. It
is used to represent the Contacts with all its properties such as id, name,
phone number and email.
2. How did you show the information coming from SQLite to your application?

First, I used the AlertDialog.Builder and EditText to get the user input. The
user needs to input their name, number and email. Once the user inserts the
data, it will be added to the database. Then the data will be retrieve using
CardView and TextView to show the newly added data.

I used the rawQuery instead of query and I retrieve anything from the
database using an object of Cursor class. We can retrieve anything from
database using an object of the Cursor class. I call a method of this class
called rawQuery and it will return a cursor with the cursor pointing to the
table. I move the cursor forward and retrieve the data. I used the sql query
“select * from “ + TABLE_CONTACTS to retrieve all the data in the contacts
tables. I also create a recyclerview adapter for the recyclerview. Once I’ve
retrieved the data from SQLite the data will show in the recyclerview. The
recyclerview comprise of Cardviews. Each CardView corresponds to the three
data coming from the user input. It includes a Filter method which would be
used to do search operations within my contacts list app.

Following is the code snippet to read the data from the SQLite Database
using a rawQuery() method in my Contact List App:

public ArrayList<Contacts> listContacts(){


String sql = "select * from " + TABLE_CONTACTS;
SQLiteDatabase db = this.getReadableDatabase();
ArrayList<Contacts> storeContacts = new ArrayList<>();
Cursor cursor = db.rawQuery(sql, null);
if(cursor.moveToFirst()){
do{
int id = Integer.parseInt(cursor.getString(0));
String name = cursor.getString(1);
String phno = cursor.getString(2);
String email = cursor.getString(3);
storeContacts.add(new Contacts(id, name, phno, email));
}while (cursor.moveToNext());
}
cursor.close();
return storeContacts;
}
Score Sheet
Question 1 Question 2 Question 3 Total Score

You might also like