I am getting the following two errors located in my code below (CheckBox) v.isChecked();:
Type mismatch: cannot convert from CheckBox to boolean
The method isChecked() is undefined for the type View
for(final int i = 0; i < setOfCheckBoxes.length; i++){
setOfCheckBoxes[i].setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
selected[i] = (CheckBox) v.isChecked();
}
});
}
Not sure what I am doing wrong and if anyone has any ideas please let me know.
Thanks!
Method calls bind tighter in order of operations than casts. Try this:
Edit: Regarding the use of ‘i’ in the inner class, use a separate variable for the captured index and the loop iteration. Try this: