Monday, 15 September 2014

android - update a row of listview in sqlite database -



android - update a row of listview in sqlite database -

i have staggeredgridview populated database baseadapter. want update contents of 1 row (one cell). getting error :

android.database.sqlite.sqliteexception: near "=": syntax error (code 1): , while compiling: update assis_notes_table set =?,ffhj=?,dfhj=? assis_note_title=dfhj @ android.database.sqlite.sqliteconnection.nativepreparestatement(native method) @ android.database.sqlite.sqliteconnection.acquirepreparedstatement(sqliteconnection.java:889) @ android.database.sqlite.sqliteconnection.prepare(sqliteconnection.java:500) @ android.database.sqlite.sqlitesession.prepare(sqlitesession.java:588) @ android.database.sqlite.sqliteprogram.<init>(sqliteprogram.java:58) @ android.database.sqlite.sqlitestatement.<init>(sqlitestatement.java:31) @ android.database.sqlite.sqlitedatabase.updatewithonconflict(sqlitedatabase.java:1572) @ android.database.sqlite.sqlitedatabase.update(sqlitedatabase.java:1520) @ com.hirak.assistere_doit.tasks_database_operations.updatenote(tasks_database_operations.java:68) @ com.hirak.assistere_doit.edit_note_frag.onclick(edit_note_frag.java:81) @ android.view.view.performclick(view.java:4438) @ android.view.view$performclick.run(view.java:18422) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5001) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601) @ dalvik.system.nativestart.main(native method)

below codes :

fragment has gridview : (on list item click, fragment opens user edit texts (everything wirking fine upto here)

notessgv.setonitemclicklistener(new staggeredgridview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { string edit_title = ((textview)view.findviewbyid(r.id.note_title_added)).gettext().tostring(); string edit_note = ((textview)view.findviewbyid(r.id.notes_grid_text)).gettext().tostring(); string color = ((textview)view.findviewbyid(r.id.color)).gettext().tostring(); edit_note_frag editnotefrag = new edit_note_frag(); bundle b = new bundle(); b.putstring("title", edit_title); b.putstring("note", edit_note); b.putstring("color", color); editnotefrag.setarguments(b); fragmentmanager fm = getfragmentmanager(); fragmenttransaction ft = fm.begintransaction(); ft.addtobackstack("enf"); ft.setcustomanimations(r.anim.slide_up, r.anim.slide_down); ft.replace(r.id.maincontent, editnotefrag, "enf"); ft.commit(); } });

fragment user update items :

@override public void onresume() { super.onresume(); title = getarguments().getstring("title"); note = getarguments().getstring("note"); color = getarguments().getstring("color"); iii = getarguments().getint("id"); edit_note.settext(note); edit_title.settext(title);

and on button click in same fragment, update called :

@override public void onclick(view v) { if (v == update){ final tasks_database_operations tasksdatabaseoperations = new tasks_database_operations(getactivity()); tasksdatabaseoperations.getwritabledatabase(); tasksdatabaseoperations.updatenote(iii, title, note, color); tasksdatabaseoperations.close(); toast.maketext(getactivity(), title, toast.length_short).show(); } }

this update query in database class"

public void updatenote(int id, string title, string note, string color) { this.getwritabledatabase(); contentvalues contentvalues = new contentvalues(); contentvalues.put(title, assis_notes_title); contentvalues.put(note, assis_notes); contentvalues.put(color, assis_notes_color); sqlitedatabase.update(assis_notes_table_name, contentvalues, assis_notes_title + "=" + title , null); sqlitedatabase.close(); }

please alter code , seek hope help you.

sqlitedatabase.update(assis_notes_table_name, contentvalues, assis_notes_title+"='" + title + "'", null);

android sqlite listview

No comments:

Post a Comment