Answer the question
In order to leave comments, you need to log in
How can I make the last fourth checkbox go into disabled mode after the first three of any checkboxes have been clicked?
As far as I understand, a function can be attached to an android checkbox only through setOnCheckedChangeListener or by specifying the android:onClick=" function attribute" (and then, write this function in MainActivity.java). Yes, that's just the problem, here's how to make sure that the condition is met: if the user clicks on three different checkboxes, then the fourth one should switch to disabled mode. According to my logic, here you need create static var count = 0, which will count the number of clicked checkboxes, that is, constantly "increment" by one unit, with each click.As soon as count becomes greater than 3, then somehow put the last checkbox remaining in the array into disabled mode by the function setEnabled(false) Yes but I have a problem like these event listeners that I bind to each individual checkbox put in if...else conditions? Or is my logic wrong in the root? Then how in general?
I tried do something like this:
if(CBA[0].isChecked()){
CBA[0].setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
for(int i=0; i < CBA.length ; i++)
if(CBA[i].isChecked())
{
count++;
}
if(count > 3){
CBA[3].setEnabled(false);
}
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question