由于某种原因,我无法从我的数据库中删除。我正在尝试将数据库中的 _ID 值与用户在 EditText 框中输入的值进行比较,如果匹配,则应删除整行。
这是我到目前为止所得到的:
private static String[] DELETION = {_ID, TITLE, TIME, DETAILS};
private Cursor delete(){
calendarData = new CalendarData(this);
SQLiteDatabase db = calendarData.getWritableDatabase();
Cursor idToDelete = db.query(true, TABLE_NAME, DELETION, _ID+" = "+deleteAnAppointment.getText(),
null, null, null, null, null);
startManagingCursor(idToDelete);
return idToDelete;
}
private void selectToDelete(Cursor cursor){
calendarData = new CalendarData(this);
SQLiteDatabase db = calendarData.getWritableDatabase();
if(cursor.moveToNext()){
db.delete(TABLE_NAME, _ID+" = "+deleteAnAppointment.getText(), null);
}
}
请任何帮助将不胜感激,我的 EditText 输入类型设置为数字
编辑:只是为了让它更清楚一点,我在 onClick 中调用这些方法以获得这样的按钮:
Cursor toDelete = delete();
selectToDelete(toDelete);
编辑(2):表创建
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
DATE + " LONG, " +
TITLE + " TEXT NOT NULL, " + TIME + " TEXT NOT NULL," + DETAILS + " TEXT NOT NULL);");
}
编辑(3):我尝试了这个以及一个简单的方法,但仍然没有:
private void deleteAppointment(){
calendarData = new CalendarData(this);
SQLiteDatabase db = calendarData.getWritableDatabase();
db.delete(TABLE_NAME, _ID+" = "+deleteAnAppointment.getText(), null);
}