我目前正在研究在 android 数据库中添加、查看和删除值,但不幸的是,我所拥有的这本书只涵盖了添加和查看部分,所以我来这里寻求帮助。
我有一个名为 DeleteEntry 的类,您可以在其中输入一个变量 moduleDelete,该变量将传递给 DeleteEntryViewModule 类。然后,此类使用此值使用此 showEvent() 方法返回该行上的所有值
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);
}
如何从构建器中获取值并将它们放入变量中,以便我可以执行此代码。
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();
}
}
谢谢