I have a listview, with around 200 items, I have implemented a custom ArrayAdapter for the checkboxes. I use a SparseBooleanArray to store the value of the boxes.
All of this works fine but I cannot seem to graphically update the checking of the boxes. If the user clicks, then the box is checked. But, if I call setChecked in my code, it has no impact on the box itself (so, even if its value is true, then it is not ticked).
I have tested by trying to set all boxes to true and no luck, even though they are all checked, they do not show that they are. Not sure what code you need to see but I have chucked in my Adapter for good measure:
class CheckBoxArrayAdapter extends ArrayAdapter<String> implements CompoundButton.OnCheckedChangeListener {
private SparseBooleanArray checkedBoxes;
Context context;
public CheckBoxArrayAdapter(Context context, int resource, List<String> objects) {
super(context, resource, objects);
checkedBoxes = new SparseBooleanArray();
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final CheckBox view = (CheckBox) super.getView(position, convertView, parent);
//if(convertView == null) {
//convertView = view.inflate(context, R.layout.list_item, null);
//}
view.setTag(position);
view.setChecked(checkedBoxes.get(position, false));
System.out.println(view.getTag() + ": " + view.isChecked());
view.setOnCheckedChangeListener(this);
return view;
}
public boolean isChecked(int position) {
return checkedBoxes.get(position, false);
}
public void setChecked(int position, boolean isChecked) {
checkedBoxes.put(position, isChecked);
notifyDataSetChanged();
}
public void toggle(int position) {
setChecked(position, !isChecked(position));
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
checkedBoxes.put((Integer) buttonView.getTag(), buttonView.isChecked());
}
}
Thanks guys!