Android: Get checked checkbox values

Solution 1:

Its simple:

static int m=0;
dualDisplay.setOnClickListener(new OnCli....{
     onClick()
     {
          if(dualcamera1.isChecked())
              m++; // you can save this as checked somewhere
          if(dualcamera2.isChecked())
              m++; // you can save this as checked somewhere
          if(dualcamera3.isChecked())
              m++; // you can save this as checked somewhere
          if(dualcamera4.isChecked())
              m++; // you can save this as checked somewhere
     }
});
if(m>2 || m<2)
      // show error message
else
      // code here

you can save checkbox's detail if its selected,in if it is checked,in for loop only.

Solution 2:

You can call isChecked() on a checkbox to get its status. If you want to count the number of checked checkboxes you could store then in an ArrayList and loop through that.

Solution 3:

If CheckBox isn't define in onCreate() method then have to use something like this:

boolean isChecked = ((CheckBox) findViewById(R.id.checkBox1)).isChecked()