I have a database to saving all data. There are 3 different activities. First activity has only one word. Second activity has many words and All data go to my database. Third activity All data are being compiled. But I have a problem. I cannot delete all data. There is a little button in 3rd activity. But when I use, My application does nothing. All data are still in my database. I want to delete all data. How can I fix?
My database query:
public void deleteAllName(int id, String name ) {
SQLiteDatabase db = this.getWritableDatabase();
String query = "DELETE FROM " + TABLE_NAME + " WHERE "
+ COL1 + " = '" + id + "' AND "
+ COL2 + " = '" + name + "'";
Log.d(TAG, "deleteName: query: " + query);
Log.d(TAG, "deleteName: Deleting " + name + " from database.");
db.execSQL(query);
}
How to get all data :
Cursor data = mDatabaseHelper.getData();
while(data.moveToNext()){
listDataId.add(data.getString(0)); //all ıds
analiste.add(data.getString(1)); // all datas
}
My little button :
sil.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for (int i = 0 ; i< listDataId.size() ; i++ ) {
int all_id = Integer.parseInt(listDataId.get(i));
String all_names = analiste.get(i);
mDatabaseHelper.deleteAllName(all_id , all_names);
}
isleme.notifyDataSetChanged();
}
});
}