0

I have created a delete function and would like for the serial number (srno) of each row after the deleted one to be decremented by 1 so that continuity without gaps is maintained. Is there any way of doing this?

public void deleteContact(Contact contact) {

    SQLiteDatabase db = this.getWritableDatabase();
    int next = contact.getSrno() + 1;

    db.delete(Util.TABLE_NAME, Util.KEY_SRNO + "=?", new String[]{String.valueOf(contact.getSrno())});

    //updateList();
    
    db.close();
}

I can use the loop:

for(Contact contact : allContacts){}

But this includes unwanted items. I just wanted to know if there is a method to retrieve the key value (srno) of the last item in the list.

  • Please add the code you already tried and why it is not working for you (error message, unexpected result, ...). Some sample data would also help: [minimal reproducalbe example](https://stackoverflow.com/help/minimal-reproducible-example) – Sander Jul 21 '20 at 08:43
  • for(Contact contact : allContacts){} I wanted to know if I could declare a starting point for the code above as I don't want redundancy, that's all I have so far :( –  Jul 22 '20 at 07:22
  • Check out [this question](https://stackoverflow.com/questions/7510219/deleting-row-in-sqlite-in-android) as a start. And the [SQLite delete](https://www.sqlite.org/lang_delete.html) syntax might be useful as well. Update your question with your attempt after that. – Sander Jul 22 '20 at 07:27
  • It's not really the deletion I'm concerned about. I want a loop to run from the item after the one deleted to the end of the list but can't figure out a method to do so. –  Jul 22 '20 at 07:54

0 Answers0