I need to get checked checkbox values when button clicked. Java Code:
dualcamera1 = (CheckBox)findViewById(R.id.Camera1_DualDisplay); dualcamera2 = (CheckBox)findViewById(R.id.Camera2_DualDisplay); dualcamera3 = (CheckBox)findViewById(R.id.Camera3_DualDisplay); dualcamera4 = (CheckBox)findViewById(R.id.Camera4_DualDisplay); dualdisplay = (Button)dialog.findViewById(R.id.DisplayDualVideo);
Get CheckBox value : CheckBox « UI « AndroidUse choice mode on a list. This list is in CHOICE_MODE_SINGLE mode, which means the items behave like checkboxes. Use choice mode on a list. This list is in CHOICE_MODE_MULTIPLE mode, which means the items behave like checkboxes.
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. Show activity on this post.
So, the method to know if the check box is checked is : (CheckBox) yourCheckBox. isChecked() it returns true if the check box is checked.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With