vendredi 6 avril 2018

How to get the number of checkboxes that can be checked in Android?

I have a activity which contains 3 different CheckBox. Now I want to validate that atleast 2 CheckBox must be selected but I am not able to achieve this. Please help.

Code:

    Boolean checkPC = chkProtectMoney.isChecked();
    Boolean checkGM = chkGrow_my_money.isChecked();
    Boolean checkMN = chkMedicalNeeds.isChecked();


      if(!(checkPC && checkGM == true) || !(checkGM && checkMN == true) || !(checkPC && checkMN == true) || !(checkPC && checkGM && checkPC == true)){

        Toast.makeText(getActivity(),R.string.two_expertise_caution,Toast.LENGTH_SHORT).show();

    } 




Aucun commentaire:

Enregistrer un commentaire