Tuesday, 15 February 2011

android - trouble in deletion from the database -



android - trouble in deletion from the database -

getting contacts phone , displaying in list view, , marking contacts , adding list view, there marked list view adding , unmarked list view deleteing.

the code used is..

@override public view getview(int position, view convertview, viewgroup parent) { view view = null; if (convertview == null) { x= position; layoutinflater inflator = context.getlayoutinflater(); view = inflator.inflate(r.layout.contactliststyle, null); final viewholder viewholder = new viewholder(); viewholder.txtname = (textview) view.findviewbyid(r.id.txtview_name); viewholder.txtnumber = (textview)view.findviewbyid(r.id.txtview_number); viewholder.selection = (checkbox)view.findviewbyid(r.id.checkbtn_selectcontact); viewholder.selection .setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { contactmodel element = (contactmodel)viewholder.selection .gettag(); element.setselected(buttonview.ischecked()); if(buttonview.ischecked()) { string selectedname=element.getname(); string selectednumber=element.getnumber(); system.out.println("etrtrt"+element.getname()); databasehandler db = new databasehandler(context); log.d("insert: ", "inserting .."); db.addcontact(new contact(selectedname, selectednumber)); } else { string selectedname=element.getname(); string selectednumber=element.getnumber(); system.out.println("number"+selectednumber); system.out.println("name"+selectedname); databasehandler db = new databasehandler(context); db.deletecontact(new contact(selectedname,selectednumber)); } } });

the code in openhelper class deleting contact is

// deleting single contact public void deletecontact(contact contact) { sqlitedatabase db = this.getwritabledatabase(); db.delete(table_contacts, key_id + " = ?", new string[] { string.valueof(contact.getid()) }); system.out.println("deleted"); db.close(); }

the contact adding database not deleting database...

try

using getwritabledatabase().delete(table_name, table_row_id + "="+rowid,null)

android

No comments:

Post a Comment