Note that there are some explanatory texts on larger screens.

plurals
  1. POListview not updating after database update and adapter.notifyDataSetChanged();
    primarykey
    data
    text
    <p>I was browsing the net for 2 days allready and tryed alot of stuff but can't seem to figure out what is wrong with this.</p> <p>I am still fairly new to the Android deevelopment so I probably missed something obvious.</p> <p>I have an app witch is using a sqllite databse to store some data and for the porpose of this Proof of concept displaying that in a listview. I can add items to the list, delete them.</p> <p>So far so good. The problem I have is when I instead of delete update a column in the databse called "deleted" and set it to 1 and then have the adapter to update the list. It seems not to work.</p> <p>If I use the delete statement it works. It updates and everything is fine but I whant to have the deleted items in the database but not to show them (So basicly "hiding" items)</p> <p>If I check the database the update itself succeded the column changes and everything so I guess it is a refresh problem because the adapter does not requery the database or something in that direction</p> <p>Listview Loader:</p> <pre><code>public void fillData() { if(lw.getAdapter() == null){ // Fields from the database (projection) // Must include the _id column for the adapter to work String[] from = new String[] { TodoTable.COLUMN_SUMMARY, TodoTable.COLUMN_ID}; String where = TodoTable.COLUMN_DELETED + " = ?"; Cursor cursor = getContentResolver().query(TodoContentProvider.CONTENT_URI,from,where,new String[] {"0"},null); // Fields on the UI to which we map int[] to = new int[] { R.id.label }; adapter = new SimpleCursorAdapter(this, R.layout.todo_row, cursor, from, to, 0); Log.v("Count",Integer.toString(cursor.getCount())); lw.setAdapter(adapter); } else adapter.notifyDataSetChanged(); } </code></pre> <p>Delete functon</p> <pre><code>@Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case DELETE_ID: /* Code for actual delete AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item .getMenuInfo(); Uri uri = Uri.parse(TodoContentProvider.CONTENT_URI + "/" + info.id); getContentResolver().delete(uri, null, null); fillData(); */ /* Code for update and hide */ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item .getMenuInfo(); Uri uri = Uri.parse(TodoContentProvider.CONTENT_URI + "/" + info.id); ContentValues values = new ContentValues(); values.put(TodoTable.COLUMN_DIRTY, 1); values.put(TodoTable.COLUMN_DELETED, 1); getContentResolver().update(uri,values,null,null); fillData(); return true; } return super.onContextItemSelected(item); } </code></pre> <p>if I put a log to the ContentProvider's query function it actually does not fire.</p> <p>Any suggestions on how to figure this out?</p> <p>If I use <code>adapter.swapCursor(cursor);</code> it works fine just just don't know if this is the correct way of doing this.</p> <pre><code>public void fillData() { // Fields from the database (projection) // Must include the _id column for the adapter to work String[] from = new String[] { TodoTable.COLUMN_SUMMARY, TodoTable.COLUMN_ID}; String where = TodoTable.COLUMN_DELETED + " = ?"; Cursor cursor = getContentResolver().query(TodoContentProvider.CONTENT_URI,from,where,new String[] {"0"},null); // Fields on the UI to which we map int[] to = new int[] { R.id.label }; if(lw.getAdapter() == null){ adapter = new SimpleCursorAdapter(this, R.layout.todo_row, cursor, from, to, 0); Log.v("Count",Integer.toString(cursor.getCount())); lw.setAdapter(adapter); } else { adapter.swapCursor(cursor); } } </code></pre> <p>Ty for the help</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