mercredi 22 novembre 2017

When recycleview scrolling parent activity button go disable

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 showbutton will disable,this how my requirement,and its working fine,but when i scroll recycle view my show button go disable.when i scroll i am getting item.ischecked() is false..can anyone help me to achieve my requrment,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

public boolean isChecked() {
    return isChecked;
}

public void setChecked(boolean isChecked) {
    this.isChecked = isChecked;
}




Aucun commentaire:

Enregistrer un commentaire