android - delete a row in sql and item in listview -
i trying delete row db. i'm using method:
public void deleteplayerbyid(int id){mdb.delete(sqlite_table, key_rowid +"="+id, null); }
called in activity :
listview.setonitemlongclicklistener(new adapterview.onitemlongclicklistener() { @override public boolean onitemlongclick(adapterview<?> av, view v, int pos, long id) { return onlonglistitemclick(v,pos,id); } protected boolean onlonglistitemclick(view v, final int pos, long id) { alertdialog.builder builder = new alertdialog.builder(androidlistviewcursoradaptoractivity.this); builder.setmessage("are sure delete?").setcancelable(false).setpositivebutton("yes", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) {bdhelper.open(); dbhelper.deleteplayerbyid(pos); log.i("listview", "onlonglistitemclick id=" + pos); displaylistview(); } })
why cannot delete selected row listview ? have method delete db , work.
try following statement able solve problem
db.delete("table","title=?",new string[]{title});
after
adapter = new entryadapter(this, items); listview.setadapter(adapter); adapter.notifydatasetchanged();
Comments
Post a Comment