android - How to update ListView when Cursor is changed? -


i below:

public class whitelistactivity extends listactivity {     private dbadapter dbhelper;     private simplecursoradapter adapter;     private cursor recordscursor;       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.whitelist);          dbhelper = new dbadapter(this);         dbhelper.open();         recordscursor = dbhelper.fetchwhitelistrecords();         startmanagingcursor(recordscursor);         string[] = new string[]{dbadapter.key_w_sender};         int[] = new int[]{r.id.text1};         adapter = new simplecursoradapter(this, r.layout.whitelist_row, recordscursor, from, to);         setlistadapter(adapter);         ...          @override         public boolean oncontextitemselected(menuitem item) {             switch(item.getitemid()) {                 case context_menu_delete_id:                 adaptercontextmenuinfo info = (adaptercontextmenuinfo) item.getmenuinfo();                 dbhelper.deletewhitelistrecord(info.id);                 adapter.changecursor(recordscursor);                 adapter.notifydatasetchanged();                 return true;             }                return super.oncontextitemselected(item);         }     

however, when context menu called , item deleted, not reflected on list view. missing?

when change cursor, need update content. simplest , recommended way create new cursor (if possible in loaded).

recordscursor = dbhelper.fetchwhitelistrecords(); adapter.changecursor(recordscursor); 

it not necessary notifydatasetchanged.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -