Professional Documents
Culture Documents
Huong Dan Lap Trinh Voi Android 22
Huong Dan Lap Trinh Voi Android 22
M:
private
private
"Books";
private
"titles";
private
SQLiteDatabase bookDB;
static final String DATABASE_NAME =
static final String DATABASE_TABLE =
static final int DATABASE_VERSION = 1;
}
@Override
public void onUpgrade(SQLiteDatabase db, int
oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS
titles");
onCreate(db);
}
}
6. Nu chng ta mun public cc d liu kiu byte nh bitmap th cc trng m
cha d liu ny nn l mt xu vi 1 content://URI cho file . y chnh l lin
kt cc ng dng khc c th truy cp v s dng d liu bitmap ny.
7. S dng Cursor thao tc trn tp d liu : query (), update(), insert(),
delete().. C th gi phng thc ContentResolver.notifyChange() bitkhi
no d liu c cp nht.
Add Book
M:
@Override
public Uri insert(Uri uri, ContentValues values) {
long rowID = bookDB.insert(DATABASE_TABLE,
"", values);
if(rowID > 0)
{
Uri mUri =
ContentUris.withAppendedId(CONTENT_URI, rowID);
getContext().getContentResolver().notifyChange(mUr
i, null);
return mUri;
}
throw new SQLException("Failed to insert new
row into " + uri);
}