I have a todo app which shows on the mainscreen a list of tasks with ListView
. I'm trying to delete a task by clicking on the done button.
But the app is deleting it by the lowest id instead of deleting the task that i tried to delete.
public void onDoneButtonClick(View view) {
ListView listView = (ListView)findViewById(R.id.list);
Cursor cursor = (Cursor) listView.getItemAtPosition(position);
int columnId = cursor.getColumnIndex(BaseColumns._ID);
int id = cursor.getInt(columnId);
Log.d("id", Float.toString(id));
String sql = String.format("DELETE FROM %s WHERE %s = %d",
TaskContract.TABLE,
TaskContract.Columns._ID,
id);
helper = new TaskDBHelper(MainActivity.this);
SQLiteDatabase sqlDB = helper.getWritableDatabase();
sqlDB.execSQL(sql);
updateUI();
Log.d("delete", sql);
}
Can someone help me to solve this?
Aucun commentaire:
Enregistrer un commentaire