vendredi 10 juillet 2015

delete entry from sqlite data base in android application. where to get the that row id to pass it ot delete function

After going through many posts I am posting my query. Not able to get proper resolution for my problem.

I am using sqlite and inserting some data (name, info etc..)

Now I get the all rows and show in list view.

Now user selects a one list entry for deletion, I have to call db.delete with id which is rowid of that particular record.

How will get the record id?

When user selects from list view I have position number which is index to the list. But not the database row id where that entry resides.

Do i have to save all ids returned when I call db.insert(table, data) when rows are created?

all examples show the implementation like

    public void deleteRow(long id) {

    db.delete(TABLE_NAME,KEY_ID + " = ?",
            new String[] { String.valueOf(id) });

    }

where should i get id from?

Aucun commentaire:

Enregistrer un commentaire