由于某种原因,我无法从我的数据库中删除。我正在尝试将数据库中的_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);
}
答案 0 :(得分:0)
我看到了你的问题。您正在调用(edittext obj).getText(),它实际上不会返回它返回的文本和可编辑的实例。之后调用.toString(),然后你将获得实际值。
如果你添加了一个日志来打印你的选择语句,这很容易被发现... fyi