statement and method to update sqlite database -
i need please. i've spent way time on , can update database if specify id number.
- click listview item , send data new activity editing
edit data , return listview activity. simple right. hmmm.
@override public void onitemclick(adapterview<?> listview, view view, int position, long id) { cursor cursor = (cursor)listview.getitematposition(position); string title = cursor.getstring(cursor.getcolumnindexorthrow(moviesdbadapter.key_title)); string barcode = cursor.getstring(cursor.getcolumnindexorthrow(moviesdbadapter.key_barcode)); string rowid = cursor.getstring(cursor.getcolumnindexorthrow(moviesdbadapter.key_rowid)); intent movieedit = new intent(getbasecontext(), movieedit.class); bundle bundle = new bundle(); bundle.putstring("rowid", rowid); bundle.putstring("title", title); bundle.putstring("barcode", barcode); movieedit.putextras(bundle); startactivity(movieedit);
receive intent listview activity:
if (this.getintent().getextras() != null) { bundle bundle = this.getintent().getextras(); edittitle.settext(bundle.getstring("title")); editbarcode.settext(bundle.getstring("barcode")); editid.settext(bundle.getstring("rowid")); }
the statement activated button:
case r.id.buttonsave: mdb.open(); contentvalues values = new contentvalues(); values.put(moviesdbadapter.key_title, title); values.put(moviesdbadapter.key_barcode, barcode); mdb.updatetitle("=?", title, barcode); mdb.close();
the method in moviedbadapter:
public boolean updatetitle(long rowid, string title, string barcode) { contentvalues args = new contentvalues(); args.put(key_title, title); args.put(key_barcode, barcode); return mdb.update(sqlite_table, args, key_rowid + "=" + rowid, null) > 0;
i know has been done death no matter try can't update database new data. hope can guys.
change code following
case r.id.buttonsave: mdb.open(); mdb.updatetitle(rowid, title, barcode); mdb.close();
Comments
Post a Comment