android - ListView中的checkbox 'Checked'滚动后恢复

标签 android listview checkbox

我遇到了以下问题:

我有一个 ListActivity,它的 ListView 由一个图标、文本和一个复选框(使用 LayoutInflater)组成。

ListView 的 Adapter 扩展了 ResourceCursorAdapter(即 ListView 的数据源是从数据库中检索的,也是每行的 Checked 状态)

一切正常,除了当我取消选中/选中任何行中的复选框时,如果我向下滚动直到修改的复选框不再可见,然后向上滚动,复选框将恢复到其原始状态。

数据库已修改,这不是问题所在(即,如果我修改一行并退出 Activity ,然后再次进入,修改后的行显示为 Ok)。

我的猜测是,这与列表的呈现方式有关,因为出于某种原因,ListView 在滚动时首次填充时“呈现”所有行的原始状态。

我一直在四处寻找这个错误,但我没有找到任何人有这个问题。我很感激你的任何建议。

最佳答案

此链接可让您深入了解您的问题

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).

关于android - ListView中的checkbox 'Checked'滚动后恢复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2574217/

相关文章:

jquery - HTML 复选框的酷替代品

android - onPause()中的AsyncTask怎么办?

java - 如何在 TextView 中显示阿拉伯文本

android - 对 Activity 和类(class)感到困惑

android - 在 Android 中创建时间轴

java - 将内容放入选项卡式 Pane 中时出现问题

AndroidAnnotations 没有生成,空 Activity

android - OnBackPress() - 使用 ZBarScannerView 时 Activity 为空白

c# - 如何将样式应用于 WPF 中的 ListView 项?

jQuery - 验证每个循环中的复选框