'How to get current sqlite id for a selected cardview from an arraylist
I'm trying to use a delete button to remove a specific contact cardview along with it's respective sqlite database entry. I managed to do so by using deleteOne method from the DatabaseHelper. It works for an int value of the contactId that I input (for example 1 in this case) however I can't figure out how to input the contactID of any desired cardview. since ContactId is an arraylist which displays all the available elements at once.
This is the delete button
mDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//int id= Integer.parseInt(Contact_id.getText.toString());
int contactId = 1;
DatabaseHelper databaseHelper = new DatabaseHelper(context);
boolean success = databaseHelper.deleteOne(contactId);
Toast.makeText(context, "Contact Deleted", Toast.LENGTH_SHORT).show();
}
});
and this is the deleteOne method in DatabaseHelper.
public boolean deleteOne(int id){
//if ContactInfo exists, it finds,deletes and returns true.
//if not found return false.
SQLiteDatabase db = this.getWritableDatabase();
String queryString = " DELETE FROM " + CONTACT_LIST + " WHERE " + COLUMN_ID + " = " + id;
Cursor cursor = db.rawQuery(queryString, null);
if(cursor.moveToFirst()){
return true;
}
else {
return false;
}
}
How can I get the correct ID from the ContactID arraylist for the desired cardview ?
Would appreciate any assistance in this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
