android - Cursor always returns empty -
in code given below ,when run app data getting written table when fetch data gives me empty cursor.any appreciated
public class todo extends activity { private checkbox chkios; edittext txtphoneno; string isc="n"; string phoneno="000"; string name="000"; context mcontect =this; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_todo); //declaration chkios = (checkbox) findviewbyid(r.id.checkbox); txtphoneno = (edittext) findviewbyid(r.id.edittextphoneno); //get_user_name sharedpreferences pref = getsharedpreferences("lin", 0); name = pref.getstring("key", null); //database_3 databaseoperations3 = new databaseoperations3(mcontect); cursor cr = do.getinformation(do); log.d("=====>", "todo"); if (cr.movetofirst()) { log.d("=====>", "todo"); { if (name.equals(cr.getstring(0))) { log.d(name, cr.getstring(0)); phoneno = (cr.getstring(1)); log.d(name, cr.getstring(0)); log.d(phoneno, cr.getstring(1)); log.d(isc, cr.getstring(2)); isc = (cr.getstring(2)); txtphoneno.settext(phoneno); } } while (cr.movetonext()); check(); }} public void check() { string s="c"; if(isc.equals(s)){ log.d("=====>", "check"); chkios.setchecked(true); } } public void cbonclick(view v) { if (chkios.ischecked()) { isc = "c"; } } public void xxx(view v) { phoneno = txtphoneno.gettext().tostring(); databaseoperations3 = new databaseoperations3(mcontect); do.putinformation(do,name,phoneno,isc); log.d("=====>", "database_3_7"); intent intenti = new intent(this, proxalertactivity.class); startactivity(intenti); } protected void sendsmsmessage() { log.d("send sms", "************"); string message = "reached"; log.d("=====>", "message"); if (isc.equals("c")&&phoneno!="000") { log.d("=====>", "eqto"); try { log.d("=====>", "try"); smsmanager smsmanager = smsmanager.getdefault(); smsmanager.sendtextmessage(phoneno, null, message, null, null); toast.maketext(getapplicationcontext(), "sms sent.", toast.length_long).show(); } catch (exception e) { log.d("=====>", "excep"); toast.maketext(getapplicationcontext(), "sms faild, please try again.", toast.length_long).show(); e.printstacktrace(); } } } } the database of app given below
public class databaseoperations3 extends sqliteopenhelper { static final int database_version = 1; static final string user_name = "user_name"; static final string user_phone = "user_ph"; static final string user_select = "user_select"; static final string databse_name = "phone_info.db"; static final string table_name = "ph_info"; public databaseoperations3(context context) { super(context, databse_name, null, database_version); log.d("database operations","database created"); } @override public void oncreate(sqlitedatabase sdb) { log.d("database operations3","table created"); sdb.execsql("create table " + table_name + "( " + user_name + " text, " + user_phone + " text, " + user_select + " text)"); } public void onupgrade(sqlitedatabase sq,int arg1,int arg2) { log.d("databasehelper", "onupgrade"); sq.execsql("drop table if exists " + table_name); oncreate(sq); } public void putinformation(databaseoperations3 dop,string name,string ph,string isc) { sqlitedatabase sq = dop.getwritabledatabase(); sq.rawquery("delete " + table_name + " " + user_name + " = ?", new string[]{name}); contentvalues cv = new contentvalues(); cv.put(user_name,name); cv.put(user_phone,ph); cv.put(user_select,isc); log.d(name,ph); } public cursor getinformation(databaseoperations3 dop) { log.d("databasehelper", "getinfo"); sqlitedatabase sq = dop.getreadabledatabase(); string[] columns = {user_name, user_phone,user_select}; cursor cr = sq.query(table_name,columns,null, null, null, null, null); return cr; } }
Comments
Post a Comment