Download presentation
Presentation is loading. Please wait.
Published byNeal Osborne Modified over 9 years ago
1
SQLite (part deux) 1 CS440
2
Traditional Model View Controller (MVC) CS440 2
3
Android: Database-centric data CS440 3
4
Useful classes SQLiteDatabase is the base class for working with a SQLite database in Android. Methods: open query: rawQuery(), execSQL() update close CS440 4 Cursor cursor = getReadableDatabase(). rawQuery("select * from todo where _id = ?", new String[] { id });
5
Cursor 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) 5
6
ListViews, ListActivities, and SimpleCursorAdapter 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 6
7
SQLiteOpenHelper 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 http://developer.android.com/reference/android/ database/sqlite/SQLiteOpenHelper.html CS440 7
8
SQLiteQueryBuilder 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)SQLiteDatabaseString[]StringString[]String 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)StringString[]StringStri ngString CS440 8
9
References Oreilly, Programming Android, Mednieks, Dornin CS440 9
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.