在Android的列表视图有问题复选框视图、复选框、问题、列表

2023-09-13 00:56:20 作者:帅到没朋友

我有一个自定义的BaseAdapter列表视图,每行包含一个复选框和三个textviews。我使用Layoutinflater夸大该行从一个XML文件中。然而,每次我选中一个复选框,许多其他复选框得到整个列表选中,而我想检查原来的复选框有时候会检查本身,有时没有。

I have a listview with custom BaseAdapter and each row contains a checkbox and three textviews. I am using Layoutinflater to inflate this row from a xml file. However, everytime I check one checkbox, many other checkboxes get checked in the whole list, whereas the original checkbox I wanted to check sometimes gets checked itself, and sometimes it does not.

用户选择一个复选框每次,我存储该复选框的附着在集合独特的价值。下一次的getView方法被调用时,我手动检查/返回内部getView视图()的基础上,如果该复选框的价值已经在收藏与否之前取消选中该复选框。但是,尽管这样,它仍然是划线的复选框,即使checkedchangelistener对于那些复选框没有启动起来。我怀疑这是由于getView观点得到重用,但不知道什么是一个很好的办法让这整个事情的工作。

Every time a user selects a checkbox, I am storing that checkbox's attached unique value in a collection. Next time the getView method is called, I manually check/uncheck the checkbox before returning the view inside getView() based on if the checkbox's value was already in the collection or not. But despite doing this, it is still marking off those checkboxes, even though the checkedchangelistener for those checkboxes is not firing up. I am doubtful this due to views getting reused in getView, but dont know what is a good way to get this whole thing to work.

推荐答案

避免如果(convertView == NULL)和其他整体的一部分 它一定会为你工作。谢谢你。

Avoid if (convertView==null) and else whole part It will definitely work for you. Thanks.