android listview 中的复选框有问题 [英] Checkboxes in android listview having problem

查看:25
本文介绍了android listview 中的复选框有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有自定义 BaseAdapter 的列表视图,每行包含一个复选框和三个文本视图.我正在使用 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.

推荐答案

避免 if (convertView==null) and else 整个部分它肯定对你有用.谢谢.

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

这篇关于android listview 中的复选框有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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