android - values fetched from database are not going to edit -
i developing database app. succeeded in inserting data data not going edit . following editing class please solve problem....
import java.util.calendar; import com.smartwallet.database.dbadapterdlicense; import android.app.activity; import android.app.datepickerdialog; import android.app.dialog; import android.database.cursor; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.datepicker; import android.widget.edittext; import android.widget.toast; public class edit_dlicense extends activity implements onclicklistener { private edittext et_cnm,et_idt,et_edt,et_lno,et_add,et_cno,et_ltype; private button bt_add; private long dlid; private cursor c; private int myear,mmonth, mday; static final int date_dialog_idi = 0; static final int date_dialog_ide = 1; private string imei_id; private datepickerdialog.ondatesetlistener mdatesetlisteneri; private datepickerdialog.ondatesetlistener mdatesetlistenere; private dbadapterdlicense dba; @override public void oncreate(bundle b) { super.oncreate(b); setcontentview(r.layout.editapp); dlid=null; bundle extras=getintent().getextras(); dlid=(b==null)? null:(long)b.getserializable("imei_id"); if(extras!=null) { dlid=extras.getlong("imei_id"); } dba=new dbadapterdlicense(this); dba.open(); et_cnm=(edittext)findviewbyid(r.id.et_cnm); et_idt=(edittext)findviewbyid(r.id.et_idt); et_edt=(edittext)findviewbyid(r.id.et_edt); et_lno=(edittext)findviewbyid(r.id.et_lno); et_add=(edittext)findviewbyid(r.id.et_add); et_cno=(edittext)findviewbyid(r.id.et_cno); et_ltype=(edittext)findviewbyid(r.id.et_ltype); et_idt.setonclicklistener(this); et_edt.setonclicklistener(this); bt_add=(button)findviewbyid(r.id.bt_save); bt_add.setonclicklistener(this); mdatesetlisteneri = new datepickerdialog.ondatesetlistener() { public void ondateset(datepicker view, int year, int monthofyear, int dayofmonth) { myear = year; mmonth = monthofyear; mday = dayofmonth; updatedisplay1(); } }; mdatesetlistenere = new datepickerdialog.ondatesetlistener() { public void ondateset(datepicker view, int year, int monthofyear, int dayofmonth) { myear = year; mmonth = monthofyear; mday = dayofmonth; //updatedisplay(); } }; final calendar c = calendar.getinstance(); myear = c.get(calendar.year); mmonth = c.get(calendar.month); mday = c.get(calendar.day_of_month); //et_cdt.settext(mday+"/"+(mmonth+1)+"/"+myear); updatedisplay1(); updatedisplay2(); updatedl(); } public void updatedl() { if(dlid!= null) { c = dba.fetchdl_imei(dlid); startmanagingcursor(c); if(c.movetofirst()) { imei_id=c.getstring(1); et_cnm.settext(c.getstring(2)); et_idt.settext(c.getstring(3)); et_edt.settext(c.getstring(4)); et_lno.settext(c.getstring(5)); et_add.settext(c.getstring(6)); et_cno.settext(c.getstring(7)); et_ltype.settext(c.getstring(8)); bt_add.settext("save"); } } } @override public void onclick(view v) { // todo auto-generated method stub if(v.equals(bt_add)) { if(dlid==null) { dba.updatedl(dlid,long.parselong(imei_id),et_cnm.gettext().tostring(),et_idt.gettext().tostring(),et_edt.gettext().tostring(),et_lno.gettext().tostring(),et_add.gettext().tostring(),et_cno.gettext().tostring(),et_ltype.gettext().tostring(),"true"); toast.maketext(edit_dlicense.this, "item updated"+c.getcount(), 2000).show(); //finish(); } finish(); } else if(v.equals(et_idt)) { showdialog(date_dialog_idi); } else if(v.equals(et_edt)) { showdialog(date_dialog_ide); } } private void updatedisplay1() { et_idt.settext(""+mday+"/"+(mmonth+1)+"/"+myear); } private void updatedisplay2() { et_edt.settext(""+mday+"/"+(mmonth+1)+"/"+myear); } @override protected dialog oncreatedialog(int id) { if(id==date_dialog_idi) { return new datepickerdialog(this, mdatesetlisteneri, myear, mmonth, mday); } else if(id==date_dialog_ide) { return new datepickerdialog(this, mdatesetlistenere, myear, mmonth, mday); } return null; } @override protected void ondestroy() { // todo auto-generated method stub dba.close(); super.ondestroy(); } }
and adapter class
import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlexception; import android.database.sqlite.sqlitedatabase; public class dbadapterdlicense { public static final string dlid = "dlid"; public static final string imei_id="imei_id"; public static final string u_name="c_nm"; public static final string i_date="i_date"; public static final string e_date = "e_date"; public static final string l_no = "l_no"; public static final string cl_no="cl_no"; public static final string c_addr="c_addr"; public static final string l_type="l_type"; public static final string exe_flag="exe_flg"; private static final string t_dlicense = "drivinglicense"; private context context; private sqlitedatabase db; private dbhelper dbhelper; public dbadapterdlicense(context context) { this.context = context; } public dbadapterdlicense open() throws sqlexception { dbhelper = new dbhelper(context); db = dbhelper.getwritabledatabase(); return this; } public void close() { dbhelper.close(); } //for appointment table public long insertdl(long imei_id,string c_nm,string i_date, string e_date,string l_no,string cl_no,string c_addr,string l_type,string exe_flg) { contentvalues values = createcontentvalues_dl(imei_id,c_nm,i_date, e_date, l_no,cl_no,c_addr,l_type,exe_flg); return db.insert(t_dlicense, null, values); } public boolean updatedl(long rowid, long imei_id,string c_nm,string i_date, string e_date,string l_no,string cl_no,string c_addr,string l_type,string exe_flg) { contentvalues values = createcontentvalues_dl(imei_id,c_nm,i_date, e_date, l_no,cl_no,c_addr,l_type,exe_flg); return db.update(t_dlicense, values, dlid + "=" + rowid, null) > 0; } public boolean updatedl_imei(long rowid, long imei_id,string c_nm,string i_date, string e_date,string l_no,string cl_no,string c_addr,string l_type,string exe_flg) { contentvalues values = createcontentvalues_dl(imei_id,c_nm,i_date, e_date, l_no,cl_no,c_addr,l_type,exe_flg); return db.update(t_dlicense, values, imei_id + "=" + rowid, null) > 0; } public boolean deletedl(long rowid) { return db.delete(t_dlicense, imei_id + "=" + rowid, null) > 0; } public cursor fetchalldl() { return db.query(t_dlicense, new string[] { dlid, imei_id,u_name,i_date,e_date,l_no,cl_no,c_addr,l_type,exe_flag}, null, null, null, null, null); } public cursor fetchdl(long rowid) throws sqlexception { cursor mcursor = db.query(true,t_dlicense, new string[] {dlid, imei_id,u_name,i_date,e_date,l_no,cl_no,c_addr,l_type,exe_flag}, dlid + "=" + rowid, null, null, null, null, null); if (mcursor != null) { mcursor.movetofirst(); } return mcursor; } public cursor fetchdl_imei(long rowid) throws sqlexception { cursor mcursor = db.query(true,t_dlicense, new string[] {dlid, imei_id,u_name,i_date,e_date,l_no,cl_no,c_addr,l_type,exe_flag}, imei_id + "=" + rowid, null, null, null, null, null); if (mcursor != null) { mcursor.movetofirst(); } return mcursor; } private contentvalues createcontentvalues_dl(long imei_id,string c_nm,string i_date, string e_date,string l_no,string cl_no,string c_addr,string l_type,string exe_flg) { contentvalues values = new contentvalues(); values.put(imei_id, imei_id); values.put(u_name, c_nm); values.put(i_date, i_date); values.put(e_date, e_date); values.put(l_no, l_no); values.put(cl_no, cl_no); values.put(c_addr, c_addr); values.put(l_type, l_type); values.put(exe_flag, exe_flg); return values; } }
is there issue of flag?? in editing. used flag here in adding values class , editing values classes. set true , set false? issues? tried th values not editing .....please suggest solution(s).
your code update seems wrong. arguments db.update should be: update(string table, contentvalues values, string whereclause, string[] whereargs)
you seem trying pass whole thing in whereclause instead of putting value using in whereargs.
i believe should be: db.update(t_dlicense, values, dlid + "= ?", new string[] { string.valueof(rowid) });
Comments
Post a Comment