android - Grabbing information from an SQLite Database: Filling in already filled fields and updating row -
checked lots of other questions , websites, couldn't find looking for. i'm making contact list practice... i'm trying give user ability update contact's info. when click on contact, fields should filled in are, not blank hint. problem fields aren't populated, else works fine fields have hints instead of text user filled in contact upon creation. here code:
contaclist.class's code...
@override protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); mdbadapter = new tagdbadapter(this); mdbadapter.open(); cursor cursor = mcursor; cursor.movetoposition(position); intent intent = new intent(this, addeditcontact.class); intent.putextra(tagdbadapter.key_rowid, id); startactivityforresult(intent, activity_edit); }
code addeditcontact.class
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); this.initlayout(); mdbadapter = new tagdbadapter(this); mdbadapter.open(); bundle extras = getintent().getextras(); mrowid = extras.getlong(tagdbadapter.key_rowid); if(mrowid != null) { mcontact = mdbadapter.fetchcontact(mrowid); m_firstnameedite.settext(mcontact.getfirstname()); m_lastnameedite.settext(mcontact.getlastname()); m_phonenumberedit.settext(mcontact.getphonenumber()); m_emailedite.settext(mcontact.getemail()); m_homephoneedite.settext(mcontact.gethomephone()); m_workphoneedite.settext(mcontact.getworkphone()); } }
fetch contact code
here code fetchcontact()
public contact fetchcontact(long rowid) throws sqlexception { contact contact = new contact(); cursor mcursor = mdb.query(true, database_table, new string[] {key_rowid, key_firstname, key_lastname, key_name, key_number, key_email, key_homephone, key_workphone}, key_rowid + "=" + rowid, null, null, null, null, null); if(mcursor != null) { mcursor.movetofirst(); } while(mcursor.movetonext()) { contact.setfirstname(mcursor.getstring(mcursor.getcolumnindexorthrow(key_firstname))); contact.setlastname(mcursor.getstring(mcursor.getcolumnindexorthrow(key_lastname))); contact.setname(mcursor.getstring(mcursor.getcolumnindexorthrow(key_name))); contact.setphonenumber(mcursor.getstring(mcursor.getcolumnindexorthrow(key_number))); contact.setemail(mcursor.getstring(mcursor.getcolumnindexorthrow(key_email))); contact.sethomephone(mcursor.getstring(mcursor.getcolumnindexorthrow(key_homephone))); contact.setworkphone(mcursor.getstring(mcursor.getcolumnindexorthrow(key_workphone))); } return contact; }
so i'm getting extras intent , getting key_rowid, , if isn't null, setting text of edittexts getters contact object got fetchcontact(long rowid) class, returns contact object. set edittexts respective getters. when in action, said, leaves fields blank, hint there.
is there i'm missing here? lot.
one potential problem thought of have 2 intents ask result activity, 1 activity_create , 1 activity_edit. maybe getting wrong intent.
have tried debugging or @ least putting log.d() in code print out values?
is mdbadapter written you? maybe there wrong fetchcontact()?
Comments
Post a Comment