Note that there are some explanatory texts on larger screens.

plurals
  1. POsqlite delete last row refresh not working
    primarykey
    data
    text
    <p>I have a long press option on my listview which will delete the long pressed db entry. The delete does actually work. If i come out of the app and go back in i am presented with my 'no rows' message. Perfect.</p> <p>In my code I first call the DBadapter method to delete a row. I then call a fetchallnotes method in the dbadapter to refresh my listview. The last row won't disappear, however, on this fetchallnotes call.. Only on the fetchallnotes call in my onCreate.</p> <p>Here is my Context Menu call which calls my DBAdapter method</p> <pre><code>db.deleteNote(info.id); getSnapz(); </code></pre> <p>This my my deleteNote method in DBAdapter</p> <pre><code>public boolean deleteNote(long rowId) { return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) &gt; 0; } </code></pre> <p>here is my getSnapz method, which is in my Main activity which is where my listview is</p> <pre><code>public void getSnapz(){ try { Cursor c = db.fetchAllNotes(); //requery cursor incase the last entry has been deleted c.requery(); startManagingCursor(c); if(c.moveToFirst()){ String[] from = new String[]{DBAdapter.KEY_TYPE,DBAdapter.KEY_WEIGHT,DBAdapter.KEY_DATE,DBAdapter.KEY_PLACE}; int[] to = new int[]{R.id.typecol,R.id.weightcol,R.id.datecol,R.id.placecol}; SimpleCursorAdapter simple = new SimpleCursorAdapter(this, R.layout.snapz_row, c, from, to); setListAdapter(simple); } } catch (Exception e) { Log.e(TAG,e.toString()); } } </code></pre> <p>And here is my fetchAllNotes method in DBAdapter</p> <pre><code>public Cursor fetchAllNotes() throws Exception{ Cursor c = db.query(DATABASE_TABLE, new String[] {KEY_ROWID,KEY_URI, KEY_DATE,KEY_TYPE,KEY_WEIGHT, KEY_PLACE}, null, null, null, null, null ); return c; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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