Java Coding in Eclipse - Jacksonville University

Download Report

Transcript Java Coding in Eclipse - Jacksonville University

1
SQLite (part deux)
CS440
Traditional Model View Controller
(MVC)
2
CS440
Android: Database-centric data
3
CS440
Useful classes
4

SQLiteDatabase is the base class for working
with a SQLite database in Android. Methods:
 open
 query:
rawQuery(), execSQL()
Cursor cursor = getReadableDatabase().
rawQuery("select * from todo where _id =
?", new String[] { id });
 update
 close
CS440
Cursor
5


A query returns a Cursor object
Cursor can represent many objects (multiple lines)
A
Cursor points to one row of the query result
 You can move between multiple lines with
Cursor.moveToNext()

Useful methods:
 getCount()
 moveToFirst(),
moveToNext(), moveToPrevious()
 isAfterLast()
 getAs*():
eg. getAsString(int columnNumber)
ListViews, ListActivities, and
SimpleCursorAdapter
6



ListViews: Views which allow to display a list
of elements
ListActivities:
specialized Activities which make the usage
of ListViews easier
SimpleCursorAdapter: maps the columns to
the Views based on the Cursor passed to it
CS440
SQLiteOpenHelper
7


Provides lifecycle framework for creating and
upgrading your application database
Useful methods:
 String
getDatabaseName()
 void onOpen(SQLiteDatabase db)
 abstract void onUpgrade(SQLiteDatabase db, int
oldVersion, int newVersion)

More on:
http://developer.android.com/reference/android/
database/sqlite/SQLiteOpenHelper.html
CS440
SQLiteQueryBuilder
8


High level abstraction for creating SQL queries
Useful Methods:
 Cursor
query(SQLiteDatabase db, String[] projectionIn, String s
election, String[] selectionArgs, String groupBy, String h
aving, String sortOrder)
 Perform
a query by combining all current settings and the
information passed into this method.
 String
buildQuery(boolean
distinct, String tables, String[] columns, String where, Stri
ng groupBy, String having, String orderBy, String limit)
CS440
References
9

Oreilly, Programming Android, Mednieks, Dornin
CS440