Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Get checked checkbox values

Tags:

android

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); 
like image 310
Kamal Avatar asked Feb 23 '12 10:02

Kamal


People also ask

How to Get selected CheckBox value in Android?

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.

How to Get CheckBox state in Android?

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.

How do you know CheckBox is checked or not in android?

So, the method to know if the check box is checked is : (CheckBox) yourCheckBox. isChecked() it returns true if the check box is checked.


2 Answers

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.

like image 90
Hiral Vadodaria Avatar answered Sep 21 '22 04:09

Hiral Vadodaria


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.

like image 31
Jon Avatar answered Sep 24 '22 04:09

Jon