我遇到以下问题:
我有一个ListActivity,它的ListView由一个图标,文本和一个复选框(使用LayoutInflater)组成.
ListView的适配器扩展了ResourceCursorAdapter(即从数据库中检索ListView的数据源,也检查每行的Checked状态)
一切都很好,除非我取消选中/选中任意一行的复选框,如果我向下滚动直到修改后的复选框不再可见,然后向上滚动,复选框将恢复到其原始状态.
数据库被修改,这不是问题(即如果我修改一行并退出活动,再次输入,则修改的行显示为Ok).
我的猜测是,这与列表的呈现方式有关,因为出于某种原因,ListView在呈现滚动时首次填充时会“呈现”所有行的原始状态.
我一直在寻找这个bug,但我没有找到任何有这个问题的人.我很感激您的任何建议.
EditText items in a scrolling list lose their changes when scrolled off the screen
List rows get recycled. Your Cursor
may have 1,000 records,but there are
not going to be 1,000 EditText
widgets created if you scroll through
the list. Rather,there will be 10 or
so,depending on how many rows are
simultaneously visible. 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).