I have created a Database in MainActivity, and want to delete or update that Database in EditActivity with method below.
private void deleteNote() {
SQLiteDatabase db;
db = openOrCreateDatabase("note.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
db.execSQL("CREATE TABLE IF NOT EXISTS note("
+ "idx INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "name TEXT,"
+ "date TEXT,"
+ "taste TEXT,"
+ "rating FLOAT" + ");");
db.execSQL("DELETE FROM note WHERE idx = " + positionInt + ";");
Toast.makeText(EditActivity.this, "Delete Success", Toast.LENGTH_SHORT).show();
db.close();
}
Above is my deleting code, but it seems doesn't work right. I see the toast message("Delete Success"), however DB still has the deleted data.
My question is: 1) Are there any wrong part in my code? 2) Are there any way to check whether the data deleted or not in Android monitor, not using Virtual device?
Many thanks! Hope some guru help me out!
idx = " + positionInt. Please understand that the position in a ListView (or any other list/grid-formic View) and a table row id are not the same thing. And they most likely will differ. By the way, the;at the end of a SQL query or command is completely useless (and string concatenation is a time consuming operation).Int positionInt = getIntent().getIntExtra("position", positionInt);Thanks for letting me know semi colon is useless here!I had brought position number from ListView in MainActivity and defined it in EditActivity which I am working at.Exactly what I understood. And, as I told you, the position in the ListView has nothing to do with the table row id.