Reputation: 751
Following code will not work because inside onChanged method, we can not access the this because the two are different object.
How can I solve this problem? Please help me. Thanks.
this.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
super.onChanged();
//this will not work
this.checkedStates = new ArrayList<CheckboxState>(this.getCount());
}
});
Upvotes: 0
Views: 61
Reputation: 6160
if the code is inside an adapter and checkedStates is a class field, just use:
registerDataSetObserver(this);
then let your adapter implements DataSetObserver
@Override
public void onChanged(){
super.onChanged();
checkedStates = new ArrayList<CheckboxState>(getCount());
}
Upvotes: 1