ListView的滚动后检查的项目不存在不存在、项目、ListView

2023-09-06 15:47:27 作者:閑人到人间

我已创建的TextView和复选框列表视图。然而滚动列表中向下(或向上)毕竟在列表中选中的项目得到选中。如何使选中的复选框保持其状态滚动后?

I have created a listview with textview and checkbox. However after scrolling the list down(or up) all the checked items in the list get unselected. How to make the checked checkboxes retain their state after scrolling?

推荐答案

的ListView回收每次滚动时的意见。这就是为什么的复选框不保留它们的状态。

ListView recycles the views every time it is scrolled. That's why the Check-boxes does not retain their states.

要完成你的任务:

在存储阵列中的检查项目。当您单击列表视图的复选框,更改数组中的特定项目的值。在您的getView方法,检查或从阵列读取值取消选中的复选框。

这样,你的复选框将保留其状态。我希望这是显而易见的。

That way your checkboxes will retain their states. I hope this is clear.