在ListView上获取复选框项时出现问题 [英] Problem getting Checkbox items on the ListView

查看:105
本文介绍了在ListView上获取复选框项时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在setListAdapter之前使用了simple_multiple_choice来创建带有复选框的列表视图.

然后我做了确定尺寸并选择了位置:


I used before setListAdapter with simple_multiple_choice to make listview with checkboxes.

And then I did to get size and chosed positions:


SparseBooleanArray checked = list.getCheckedItemPositions();
cont = list.getCheckedItemPositions().size();

if (checked.get(i))
{
...


但是现在我需要对布局进行更多控制,所以我在xml上执行listview,例如:


But now I needed more control on the layout, so i''m doing the listview on the xml, something like:

<listview>
<checkboxes id=.../>
</listview>



对这些ID使用setAdapter.

正确填充了列表视图(如以前一样),问题是,现在SparseBooleanArray不起作用. Thar变量"cont",给我0,而"checked"为空.

确保列表"正确:



using setAdapter to those ids.

The listview is correctlyt populated (as before), problem is, now the SparseBooleanArray don''t work. Thar variable ''cont'', gives me 0, and ''checked'' is null.

To make sure that ''list'' is ok:

int len = list.getCount();



它给了我正确的价值.

是什么问题?



It gives me a right value.

What''s the problem?

推荐答案

检查以下内容:
check this: http://stackoverflow.com/questions/3996938/why-is-listview-getcheckeditempositions-not-returning-correct-values[^]

It''s a common bug.


这篇关于在ListView上获取复选框项时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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