Scrolling list of EditText items loses user edits


Last Updated:

  1. ianww

    ianww Member This Topic's Starter

    Joined:
    Jun 11, 2010
    Messages:
    5
    Likes Received:
    0
    I have a long scrolling list of EditText items created by a SimpleCursorAdapter and prepopulated with values from an SQLite database.

    I make this by:

    cursor = db.rawQuery("SELECT _id, criterion, localweight, globalweight FROM " + dbTableName + " ORDER BY criterion", null);

    startManagingCursor(cursor);

    mAdapter = new SimpleCursorAdapter(this, R.layout.weight_edit_items, cursor, new String[]{"criterion","localweight","globalweight"}, new int[]{R.id.criterion_edit, R.id.localweight_edit, R.id.globalweight_edit});

    this.setListAdapter(mAdapter);


    The scrolling list is several screens long. The items display OK - scrolling through them shows that each has the correct value from the database.

    I can make an edit change to any of the EditTexts and the new text is accepted and displayed in the box.

    But...if I then scroll the list far enough to take the edited item off the screen, when I scroll back to look at it again its value has returned to what it was before I made the changes, ie. my edits have been lost.

    In trying to sort this out, I've done a getText to look at what's in the EditText after I've done my edits and getText returns the original text, even though its displaying my new text. It seems that the EditText has only accepted my edits superficially and they haven't been bound to the EditText.

    Can anyone please tell me what's going on here and what I need to do to force the EditText to retain its edits?

    Thanks

    Ian
     

    Advertisement
  2. ianww

    ianww Member This Topic's Starter

    Joined:
    Jun 11, 2010
    Messages:
    5
    Likes Received:
    0
    I've had a great answer to this question elsewhere from Mark Murphy (Android author, commonsware.com) - In part: "Rows get recycled, and the binding operation will replace the old EditText value with a new value from the Cursor for whatever row just scrolled onto the screen, replacing whatever was there before (previous value from the database or a user-edited value)."

    All makes sense now. I'll need to do a rework or redesign to get around that restriction.
     

Share This Page

Loading...