Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i auto-decrement primary key value in SQlite Android
    primarykey
    data
    text
    <p>I have a tables in android SQLite and I am trying to figure out how to reset the <code>KEY_ID</code>, I read that: <code>DELETE FROM tablename</code> should delete everything and reset the autoincremement field back to 0 but when I do this it just deletes the data. When a new record is inserted the autoincrement picks up where it left off before the delete. I have implemented a <code>longitemclicklistner</code> on list, it gets the position and i want to delete the particular item from the list. Here is my code</p> <pre><code>public void deleteContact(Contact contact) { SQLiteDatabase db = this.getWritableDatabase(); getWritableDatabase().delete(TABLE_CONTACTS, KEY_ID + " = ?", new String[] { String.valueOf(contact.getID()) } ); db.close(); } </code></pre> <p>Here is the code in <code>onlongclicklistner</code></p> <pre><code> public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View arg1, int pos, long id) { // TODO Auto-generated method stub Log.v("long clicked","pos"+" "+pos); final int p=pos+1; final AlertDialog.Builder b = new AlertDialog.Builder(MainActivity.this); b.setIcon(android.R.drawable.ic_dialog_alert); b.setMessage("Are you sure you want to DELETE this Entry?"); b.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // continue with delete db.getWritableDatabase(); db.deleteContact(db.getContact(p)); Intent i = new Intent(MainActivity.this,MainActivity.class); startActivity(i); } }); b.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }); b.show(); } </code></pre> <p>The problem is, <code>id1</code> is created then <code>id2</code> is created but when i delete <code>id2</code> and create a new contact, it gets the <code>id3</code>. i want it to get <code>id2</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload