滚动后列表视图的选中项不存在 [英] Listview's checked items not there after scrolling

查看:26
本文介绍了滚动后列表视图的选中项不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有文本视图和复选框的列表视图.但是,向下(或向上)滚动列表后,列表中的所有选中项目都将取消选择.如何使选中的复选框在滚动后保持其状态?

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.

这篇关于滚动后列表视图的选中项不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆