Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mobile Applications (Android Programming)

Similar presentations


Presentation on theme: "Mobile Applications (Android Programming)"— Presentation transcript:

1 Mobile Applications (Android Programming)
Semester II Dr. Saman Mirza Abdullah

2 Class Objective The objective of this class is:
To explain the concept of databased in Android based application. To describe the classes and methods that work with the database package in Android. To describe the SQLite database in Android based applications. Mobile Application - Ishik

3 SQLite Architecture 1. Packages
There are two packages supporting data manipulating inside the Android platform: android.database, that contains all necessary classes for working with databases. (content provider) android.database.sqlite, that specified for SQLite databases. Mobile Application - Ishik

4 SQLite Architecture 2. A super Subclass
To achieve database with SQLite, you need a super() subclass from the SQLiteOpenHelper class. It has two main parameters: Name of the database. Version of the database. A developer need to override to methods: onCreat() ; when the database crated for the first time. onUpgread () ; when changes in database needed. Mobile Application - Ishik

5 SQLite Architecture 2. A super Subclass
To Access SQLiteDatabase, two methods are used in the class SQLiteOpenHelper : getReadableDatabse() ; to access the database in the read only status. getWriteableDatabse() ; to access the database in the editable status besides the readable. One of these two methods should be clearly defined. Mobile Application - Ishik

6 Mobile Application - Ishik

7 SQLite Architecture 3. SQLite Database
SQLiteDatabase is the base class for working with a SQLite database in Android and provides methods to open, query, update and close the database. More specifically SQLiteDatabase provides the insert(), update(), and delete methods. It provides the execSQL() to execute SQL statements directly. Mobile Application - Ishik

8 Creating Database In general, for any database you should have:
Database name Table name Column name. Student.db (database) Student (Table) ID NAME SURNAME MARKS 1 AAA A1 87 2 BBB B1 88 3 CCC C1 90 4 DDD D1 77 Mobile Application - Ishik

9 Adding Database Variables
Mobile Application - Ishik

10 Creating Tables Mobile Application - Ishik

11 Main Activity? So far, the code written in created class.
Changes should be done in Main Activity. Mobile Application - Ishik

12 Inserting Data The insertion required a place where mobile users need to key in records. A developer need to build or design a layout that comes proper with the attributes of the created table. Colors, font types and sizes are not much important in the viewpoint of the code. Mobile Application - Ishik

13 Layout Design For the proposed example, a developer need to design a layout, for example, as shown here. Three view text. Three plain text Name: Surname: Marks: Mobile Application - Ishik

14 Layout Design For the proposed example, a developer need to design a layout, for example, as shown here. Three view text. Three plain text Buttons (Add, Edit, View, and Delete) Mobile Application - Ishik

15 Main Activity for Three EditTexts
For the added three EditTExts and one Button, developer need to add four variables and cast them. Mobile Application - Ishik

16 Button Function A method should be given to function to do the following jobs, when clicked. setonClickListener() method. Call insert() method. (has three parameters) String name; String surname; String Marks. Link the casted EditText with the variables of the insert() method, through getText() method, and toString() method Mobile Application - Ishik

17 Insert Data Function Class file
Mobile Application - Ishik

18 Insert Data Function Main Activity file
Mobile Application - Ishik

19 Insert Data Function Main Activity-Button
Mobile Application - Ishik

20 Insert Data Function Main Activity-Button
Mobile Application - Ishik

21 Class End Mobile Application - Ishik


Download ppt "Mobile Applications (Android Programming)"

Similar presentations


Ads by Google