Są to identyfikatory w moim stole:uzyskać pojedynczy wiersz z tabeli
KEY_ID(autoincremented integer primary key) KEY_NAME(text) KEY_PH_NO(text)
1 james 1234567890
2 kristein 6484996755
3 Roen 4668798989
4 Ashlie 6897980909
Co chcę wiedzieć, w jaki sposób mogę uzyskać pojedynczy rekord z tabeli na podstawie unique(KEY_ID)
, w tym I zbudowaliśmy getContact()
metody takie jak to,
Contact getContact(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
KEY_NAME, KEY_PH_NO }, KEY_ID + "=?",
new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
Contact contact = new Contact(Integer.parseInt(cursor.getString(0)),
cursor.getString(1), cursor.getString(2));
// return contact
return contact;
}
And Contact
to klasa, gdzie mam ustawić cały getter i metody setter dla wszystkich atrybutów.
Prosimy o pomoc przy pełnym kodzie.
tenx .. to był pomocny .. –