安卓的ListView选中复选框无意 [英] Android: ListView CheckBox checked unintentionally
问题描述
我有一个ListView也就是上面一个页脚酒吧标题栏和布局下方的布局。 ListView中的每一行包含与侧CheckBox和TextView的一侧的LinearLayout。现在,当我有一次可以显示更多行,你当然可以向下滚动或向上。然而,一旦我向下滚动或向上的第一和/或最后的CheckBox正在自动检查。我的手指是隔靴搔痒,你会选择复选框。可能是什么原因?
请注意我用code此处的http://www.anddev.org/checkbox_text_list___extension_of_iconified_text_tutorial-t771.html
I have a ListView which is layout below a header bar and layout above a footer bar. Each row of the ListView contains a LinearLayout with a CheckBox and TextView side by side. Now, when I have more rows that can be shown at a time, you can of course scroll down or up. However, once I scroll down or up the first and / or last CheckBox is being checked automatically. My finger is nowhere near where you would select the check box. What could be causing this? Note I used code here: http://www.anddev.org/checkbox_text_list___extension_of_iconified_text_tutorial-t771.html
推荐答案
简要展望到相关链接下psented code $ P $,我可以看到以下内容:
Looking briefly into code presented under link in question I can see the following:
public View getView(int position, View convertView, ViewGroup parent){
CheckBoxifiedTextView btv;
if (convertView == null) {
btv = new CheckBoxifiedTextView(mContext, mItems.get(position));
} else { // Reuse/Overwrite the View passed
// We are assuming(!) that it is castable!
CheckBoxifiedText src = mItems.get(position);
btv = (CheckBoxifiedTextView) convertView;
btv.setCheckBoxState(src.getChecked()); // set checked state
btv = (CheckBoxifiedTextView) convertView;
btv.setText(mItems.get(position).getText());
}
return btv;
}
正如你所看到的视图滚动过程中重复使用,复选框的状态设置与方法的 setCheckBoxState 。
然后在 CheckBoxifiedTextView 您可以找到:
public void setCheckBoxState(boolean bool)
{
mCheckBox.setChecked(mCheckBoxText.getChecked());
mCheckBoxText.setChecked(true); // <-- HERE !
}
其中第四行有setChecked(真正)硬盘codeD这可能导致该问题。
where in 4th line there is setChecked(true) hardcoded which might be causing the issue.
这篇关于安卓的ListView选中复选框无意的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!