Note that there are some explanatory texts on larger screens.

plurals
  1. POGrabbing information from an SQLite Database: Filling in already filled fields and updating row
    primarykey
    data
    text
    <p>checked lots of other questions and websites, couldn't really find what I was looking for. I'm making a contact list for practice... what I'm trying to do is give the user the ability to update the contact's info. When they click on a contact, the fields should be filled in as they already are, not be blank with a Hint. Problem now is that the fields aren't populated, everything else works just fine but all the fields just have hints instead of the text the user filled in for the contact upon creation. Here is the code:</p> <p>ContacList.class's code...</p> <pre><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></pre> <p>Code for the AddEditContact.class</p> <pre><code>@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()); } } </code></pre> <p>Fetch contact code</p> <p>Here is the code for fetchContact()</p> <pre><code>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; } </code></pre> <p>So I'm getting the extras from the intent and getting the KEY_ROWID, and if it isn't null, setting the text of the EditTexts to the getters for the contact object I got from the fetchContact(long rowId) class, which returns a Contact object. Then I set all the EditTexts to their respective getters. But when in action, like I said, it just leaves all the fields blank, with just a Hint there.</p> <p>Is there something I'm missing here? Thanks a lot.</p> <p>One potential problem I thought of was that I have two intents which ask for a result from this activity, one for ACTIVITY_CREATE and one for ACTIVITY_EDIT. Maybe its getting the wrong intent.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload