What I want to do is if April and May have a due amount then a user cannot select May if April is not selected . First, a user has to select April then the May checkbox will get enabled . If May is selected then June will get enabled .
I am not able to get position of the checkboxes so that I can do the same.
@Override
public void onBindViewHolder(@NonNull FeeHolder holder, int position) {
holder.textView_fee.setText(Integer.toString(list.get(position).getFeeAmount()));
holder.textView_due.setText(Integer.toString(list.get(position).getDueAmount()));
holder.checkBox.setText(list.get(position).getInstallmentName());
holder.checkBox.setTag(Integer.toString(position));
arrayList.add(holder.checkBox);
/*if (holder.checkBox.isChecked()) {
arrayList.add(holder.checkBox);
}*/
holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});
Add a selected
property (with getters and setters) to your list
array and here's a code fragment to play with.
if (position > 0) {
YourObject obj = list.get(position - 1);
if(obj.dueAmount() > 0) {
if(obj.isSelected()) {
holder.checkBox.setEnabled(true)
} else {
holder.checkBox.setEnabled(false)
}
} else {
holder.checkBox.setEnabled(true)
}
}
Then, on your setOnCheckedChangeListener
, update your object's selected
property accordingly.
PS: This applies a chain effect if previous items have dueAmount > 0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.