0

I want to allow only one check box to select in recyclearview if i select another one previously selected checkbox have to unchecked i code is writen in below help me to how to complete this ....?

RecyMyadptr

public class RecyMyadptr extends 
RecyclerView.Adapter<RecyMyadptr.RecyMyHolder> {
ArrayList<Data> dataaaa=new ArrayList<>();
Context context1;
int i=0;
static int selectedPosition = -1;
RecyMyadptr(Context context , ArrayList<Data> data)
{
    this.dataaaa=data;
    this.context1=context;
}
@NonNull
@Override
public RecyMyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.card, parent, false);

    return new RecyMyHolder(view);
}

@Override
public void onBindViewHolder(@NonNull final RecyMyHolder holder, final int position) {

    final Data date= dataaaa.get(position);
    holder.textView2.setText(date.getName());
    holder.textView.setText(date.getId());
    holder.checkBox.setOnCheckedChangeListener(null);
    holder.checkBox.setChecked(date.isSelected());
    holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
       @Override
       public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            date.setSelected(b);
        }
    });

}
@Override
public int getItemCount() {
    return dataaaa.size();
}
class RecyMyHolder extends RecyclerView.ViewHolder
{
    TextView textView,textView2;
    CheckBox checkBox;
    public RecyMyHolder(final View itemView) {
        super(itemView);
        textView=itemView.findViewById(R.id.text1id);
        textView2=itemView.findViewById(R.id.text2id);
        checkBox=itemView.findViewById(R.id.checkboxid);
    }
}

}

Community
  • 1
  • 1

0 Answers0