i got an issue with my adapter. Here is the code:
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
final ViewHolder viewHolder;
View view = convertView;
if (view == null) {
view = LayoutInflater.from(mContext).inflate(R.layout.row, parent, false);
viewHolder = new ViewHolder();
viewHolder.textTitle = (TextView) view.findViewById(R.id.title);
viewHolder.checkBox = (CheckBox) view.findViewById(R.id.checkBox);
viewHolder.checkBox.setTag(position);
view.setTag(viewHolder);
viewHolder.imageView = (ImageView) view.findViewById(R.id.activity_googlecards_card_imageview);
} else {
viewHolder = (ViewHolder) view.getTag();
viewHolder.checkBox.getTag(position);
}
viewHolder.textTitle.setText(getItem(position).getTitle());
viewHolder.checkBox.setChecked(myIntegerArrayList.contains(position));
viewHolder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
myIntegerArrayList.add(position);
} else {
myIntegerArrayList.remove((Object) position);
}
}
});
return view;
}
private static class ViewHolder {
TextView textTitle;
CheckBox checkBox;
}
The checkbox itself works fine.. I mean, the position is correctly added to my arraylist but if (assuming i checked the item at position 0) i scroll to bottom, then, scroll back to top the item 0 return unchecked even if the position is into my arraylist (verified with logs)