Hello to everyone, after some effort I finally succeeded fixing the SQLite Row ID number. There main thing is that the row ID, it is handled by the SQLite at low level, so you shouldn't really touch it. The workaround is to work with the position of row, instead of the rowId. We do that, like this:
- To show in the sqlite result view, you have to change the method that returns the string that it is going to display: in my case the method is called getData()
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
// assembles the result
result = result + (c.getPosition()+1)/*getString(iRow)*/ + "- " + c.getString(iFecha) + " " + c.getString(iEstacion) + " km:" + c.getString(iKilometros) + " lts:" + c.getString(iLitros) + " cons:" + c.getString(iConsumo) + "\n";
If you take a look pretty close, you have to change the getString(iRow) to getPosition()+1
That's only one part of the magic, because when you delete, you have to delete the row that corresponds to the POSITION that is displayed (the rowID is not displayed anymore). Now, the user will enter the number of the position of the row, but that number will not always (almost never) be the same as the rowID because once you start deleting and entering a new Row the RowID will continue to increment, independtly of the position of the row.
So, the change you have to make in the deleteEntry() method is the following:
String[] columns = new String[]{KEY_ROWID, KEY_NAME, KEY_HOTNESS};
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
int rowId = -1;
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
if(rowPos == c.getPosition()+1)
rowId=Integer.valueOf(c.getString(0));
}
if (rowId == -1)
return -1;
ourDatabase.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null);
return rowId;
This way, you look for the rowID that corresponds to the position entered by the user, and you delete that row.
I hope this was useful to all of you.
Rock & roll.
Marco Aponte.