android - how to update list after deleting an item? -


i want delete item arraylist , update after delete. query performing delete operation list not getting updated. below onitemlongclicklistener code.

listview.setonitemlongclicklistener(new adapterview.onitemlongclicklistener() {         @override         public boolean onitemlongclick(adapterview<?> parent, view view, int position, long id) {              help.deleteentry(position);             adapter.remove(adapter.getitem(position));             adapter.notifydatasetchanged();              toast.maketext(search.this, "delete..", toast.length_short).show();             return true;         }     }); 

delete code of databasehelper.

 public void deleteentry(long id) {      // delete row in user table based on id      sqlitedatabase db = this.getreadabledatabase();     db.delete(table_name,key_id + " = " + id,null);  } 

i notice 2 things here first don't pass position delete row database id auto increment , secondly delete should getwriteabledatabase()

so code should

listview.setonitemlongclicklistener(new adapterview.onitemlongclicklistener() {         @override         public boolean onitemlongclick(adapterview<?> parent, view view, int position, long id) {              obj obj = adapter.getitem();             help.deleteentry(obj.getid());             adapter.remove(adapter.getitem(position));             adapter.notifydatasetchanged();              toast.maketext(search.this, "delete..", toast.length_short).show();             return true;         }     });  

in deleteentry() use

sqlitedatabase db = this.getwriteabledatabase(); 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -