I have a RecyclerView grid adapter contains checkboxes and a show button in parent activity.if we select checkbox parent activity show button to enable and if we unchecked checkbox show button will disable, this how my requirement, and its working fine, but when I scroll recycle view my show button to disable. When I scroll I am getting item.isChecked()
is false..can anyone help me to achieve my requirement, pls explain
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
try {
final GridViewHolder viewHolder = (GridViewHolder) holder;
final MyList item = items.get(position);
viewHolder.myCheckBox.setTag(position);
viewHolder.myCheckBox.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton,
boolean b) {
item.setChecked(b);
if (item.isChecked())
Count++;
else
Count--;
if (Count > 0) {
((MyActivity)context).showButton().setEnabled(true);
} else {
((MyActivity)context).showButton().setEnabled(false);
}
}
});
viewHolder.myCheckBox.setChecked(item.isChecked());
} catch (Exception e) {
e.printStackTrace();
}
}
In my pojo list class i written two functions for identy checkbox return values
boolean isChecked;
public boolean isChecked() {
return isChecked;
}
public void setChecked(boolean isChecked) {
this.isChecked = isChecked;
}
ViewHolder inner class in adapter
public class GridViewHolder extends RecyclerView.ViewHolder {
private CheckBox myCheckBox;
public GridViewHolder(final View parent) {
super(parent);
myCheckBox = (CheckBox) parent.findViewById(myCheckBox);
((ProductListingActivity)context).showButton().setEnabled(false);
parent.setOnClickListener(GridAdapterMy.this);
}
}