Android: ListView CheckBox Checked Unintentionally
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,
Solution 1:
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;
}
As you can see the view is reused during scroll and checkbox state is set with method setCheckBoxState. Then in CheckBoxifiedTextView you can find:
public void setCheckBoxState(boolean bool)
{
mCheckBox.setChecked(mCheckBoxText.getChecked());
mCheckBoxText.setChecked(true); // <-- HERE !
}
where in 4th line there is setChecked(true) hardcoded which might be causing the issue.
Post a Comment for "Android: ListView CheckBox Checked Unintentionally"