我需要根據來自POJO類的布爾值自動檢查我的recyclerview複選框。以下是我的課程細節。自動檢查或取消選中具有布爾值的RecyclerView複選框
HealthStatusCheck.java:
public class HealthStatusCheck {
private int id;
private int donorID;
private boolean q1;
private boolean q2;
private boolean q3;
private boolean q4;
private boolean q5;
private boolean q6;
private boolean q7;
private boolean q8;
private boolean q9;
private boolean q10;
private boolean q11;
private boolean q12;
private boolean q13;
private boolean q14;
private boolean q15;
private boolean q16;
private boolean q17;
private boolean q18;
private boolean q19;
private boolean q20;
public HealthStatusCheck() {}
public HealthStatusCheck(int id, int donorID, boolean q1, boolean q2, boolean q3, boolean q4, boolean q5, boolean q6,
boolean q7, boolean q8, boolean q9, boolean q10, boolean q11, boolean q12, boolean q13,
boolean q14, boolean q15, boolean q16, boolean q17, boolean q18, boolean q19, boolean q20) {
this.id = id;
this.donorID = donorID;
this.q1 = q1;
this.q2 = q2;
this.q3 = q3;
this.q4 = q4;
this.q5 = q5;
this.q6 = q6;
this.q7 = q7;
this.q8 = q8;
this.q9 = q9;
this.q10 = q10;
this.q11 = q11;
this.q12 = q12;
this.q13 = q13;
this.q14 = q14;
this.q15 = q15;
this.q16 = q16;
this.q17 = q17;
this.q18 = q18;
this.q19 = q19;
this.q20 = q20;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getDonorID() {
return donorID;
}
public void setDonorID(int donorID) {
this.donorID = donorID;
}
public boolean isQ1() {
return q1;
}
public void setQ1(boolean q1) {
this.q1 = q1;
}
public boolean isQ2() {
return q2;
}
public void setQ2(boolean q2) {
this.q2 = q2;
}
public boolean isQ3() {
return q3;
}
public void setQ3(boolean q3) {
this.q3 = q3;
}
public boolean isQ4() {
return q4;
}
public void setQ4(boolean q4) {
this.q4 = q4;
}
public boolean isQ5() {
return q5;
}
public void setQ5(boolean q5) {
this.q5 = q5;
}
public boolean isQ6() {
return q6;
}
public void setQ6(boolean q6) {
this.q6 = q6;
}
public boolean isQ7() {
return q7;
}
public void setQ7(boolean q7) {
this.q7 = q7;
}
public boolean isQ8() {
return q8;
}
public void setQ8(boolean q8) {
this.q8 = q8;
}
public boolean isQ9() {
return q9;
}
public void setQ9(boolean q9) {
this.q9 = q9;
}
public boolean isQ10() {
return q10;
}
public void setQ10(boolean q10) {
this.q10 = q10;
}
public boolean isQ11() {
return q11;
}
public void setQ11(boolean q11) {
this.q11 = q11;
}
public boolean isQ12() {
return q12;
}
public void setQ12(boolean q12) {
this.q12 = q12;
}
public boolean isQ13() {
return q13;
}
public void setQ13(boolean q13) {
this.q13 = q13;
}
public boolean isQ14() {
return q14;
}
public void setQ14(boolean q14) {
this.q14 = q14;
}
public boolean isQ15() {
return q15;
}
public void setQ15(boolean q15) {
this.q15 = q15;
}
public boolean isQ16() {
return q16;
}
public void setQ16(boolean q16) {
this.q16 = q16;
}
public boolean isQ17() {
return q17;
}
public void setQ17(boolean q17) {
this.q17 = q17;
}
public boolean isQ18() {
return q18;
}
public void setQ18(boolean q18) {
this.q18 = q18;
}
public boolean isQ19() {
return q19;
}
public void setQ19(boolean q19) {
this.q19 = q19;
}
public boolean isQ20() {
return q20;
}
public void setQ20(boolean q20) {
this.q20 = q20;
}
}
以上就是我的POJO類。現在我需要根據分配給POJO類的布爾值設置recyclerview複選框。在我的recyclerview適配器中,此POJO類可用。
這裏是我的適配器代碼:
public class DonorHealthStatusAdapter extends RecyclerView.Adapter<DonorHealthStatusAdapter.HealthViewHolder> {
private Context context;
private ArrayList<DonorHealthStatusQuestionare> questionares;
private HealthStatusCheck healthStatusCheck;
public DonorHealthStatusAdapter(Context context, ArrayList<DonorHealthStatusQuestionare> questionares,
HealthStatusCheck healthStatusCheck) {
this.context = context;
this.questionares = questionares;
this.healthStatusCheck = healthStatusCheck;
}
@Override
public HealthViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_donor_health_info, parent, false);
return new HealthViewHolder(view);
}
@Override
public void onBindViewHolder(final HealthViewHolder holder, int position) {
DonorHealthStatusQuestionare questionare = questionares.get(position);
holder.tv_questions.setText(questionare.getQuestions());
holder.cbYes.setOnCheckedChangeListener(null);
holder.cbNo.setOnCheckedChangeListener(null);
}
@Override
public int getItemCount() {
return questionares.size();
}
public class HealthViewHolder extends RecyclerView.ViewHolder {
CardView cardView;
TextView tv_questions;
CheckBox cbYes, cbNo;
public HealthViewHolder(View itemView) {
super(itemView);
cardView = itemView.findViewById(R.id.card_view_health_status_rv);
tv_questions = itemView.findViewById(R.id.tv_eligibility_question);
cbYes = itemView.findViewById(R.id.checkBoxYes);
cbNo = itemView.findViewById(R.id.checkBoxNo);
}
}
}
那麼是什麼問題?你有布爾人......你有複選框。還需要什麼? – Wizard
我需要在回收視圖中根據布爾值設置選擇。回收利用者視圖中有20行。每行有複選框,我需要選擇或不選擇。 –
每20行有20個不同的值。從我的適配器中選擇設置後,所有複選框都處於選中狀態。 –