定制列表视图包含Checkboxs滚动列表项目时 [英] Customized Listview with items containing Checkboxs when Scrolling the List

查看:83
本文介绍了定制列表视图包含Checkboxs滚动列表项目时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的2 TextViews定制列表视图,并在每个项目有一个复选框问题,problme正在滚动列表视图时,检查的项目得到选中随机,反之亦然,任何人都可以帮助定义一个定制的适配器来解决这个的问题,我将非常感激。

I have a problem with my customized Listview with 2 TextViews and a CheckBox in each item, the problme is when scrolling the Listview, the checked items get unchecked randomly and vice versa, can anyone help to define a customized Adapter to solve this problem, i'll be so thankful

推荐答案

我有同样的问题,我解决如下:

I had the same problem and I solved as follows:

我有一个布尔变量的 isCheckedByUser 。在适配器,每次我做一些与复选框,我这个变量设置为false首先,做所有的事情,我必须与复选框,并实现再设置变量。然后,在方法的 onCheckedChanged 我检查,如果这个变量是真实的,如果是,意味着用户要修改状态,所以我做任何它所需用的复选框。

I have a boolean variable isCheckedByUser. In the adapter, everytime I do something with the checkbox, i set this variable to false first, do all the things I have to with the checkbox, and set the variable to true again. Then, in the method onCheckedChanged I check if this variable is true, if so, means that the user wanted to modify the state, so I do whatever its needed with the checkbox.

在实际上,这个问题不是那么随机。列表视图重用细胞,所以这就是为什么你好像复选框被选中随机。

In fact, this problem is not so "random". The listview reuses the cells, so that's why for you seems like the checkboxes are unchecked randomly.

这篇关于定制列表视图包含Checkboxs滚动列表项目时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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