I'm trying to initialize a checkbox listview from an array. To do so I'm looping through listview items and checking if the item exists or doesn't, if it does then I set it to checked. Thing is it doesn't really work as expected. Internally everything works just fine, the result array is correct, but visually it doesn't display the checkboxes in their correct state.
This is the function which initializes the checkboxes, it is called by onCreate and onResume methods.
public void init()
{
View v;
CheckBox checkbox;
for (int i = 0; i < LIST.getCount(); i++) {
v = LIST.getAdapter().getView(i, null, null);
checkbox = (CheckBox)v.findViewById(R.id.checkbox);
MyClass c = (MyClass) adapter.getItem(i);
if(List_to_compare.contains(c)) {
Log.i("Before", String.valueOf(checkbox.isChecked())); //returns false
checkbox.setChecked(true);
Log.i("After", String.valueOf(checkbox.isChecked())); //returns true
}
}
}
But the checkbox is not visually checked. If more code is needed, let me know, really struggling with this one.
Aucun commentaire:
Enregistrer un commentaire