I’m currently working on adding, viewing and removing values in an android database but unfortunately the book I have only covers the adding and viewing part so I’ve come here for help.
I have a class called DeleteEntry which you enter a variable moduleDelete which get passed through to the class DeleteEntryViewModule. This class then uses this value to return all values on that row using this showEvent() method
private void showEvents(Cursor cursor) {
StringBuilder builder = new StringBuilder("Saved Events:\n");
while (cursor.moveToNext()){
long id = cursor.getLong(0);
String module = cursor.getString(1);
String day = cursor.getString(2);
String starttime = cursor.getString(3);
String duration = cursor.getString(4);
String typeofsession = cursor.getString(5);
String room = cursor.getString(6);
builder.append(id).append(": ");
builder.append(module).append(": ");
builder.append(day).append(": ");
builder.append(starttime).append(": ");
builder.append(duration).append(": ");
builder.append(typeofsession).append(": ");
builder.append(room).append("\n ");
}
TextView text = (TextView) findViewById(R.id.text);
text.setText(builder);
}
How do I take the values from the builder and place them into variables so I can execute this code.
private void removeEvent (String module, String day, String starttime, String duration, String typeofsession, String room){
try{
SQLiteDatabase db = events.getWritableDatabase();
ContentValues values = new ContentValues ();
values.put(DAY, day);
values.put(MODULE, module);
values.put(STARTTIME, starttime);
values.put(DURATION, duration);
values.put(TYPEOFSESSION, typeofsession);
values.put(ROOM, room);
db.replaceOrThrow(TABLE_NAME, null, values);
}catch(SQLiteException ex){
Toast toast = Toast.makeText(this, "Broken", 10);
toast.show();
}
}
Thanks
Try using below code instead of db.replaceOrThrow
Can you explain why you are using db.replaceOrThrow ??