Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to receive a event on android checkbox check change?

What would be the correct way of receiving and sending an event when a check box gets enabled or disabled?

In C# I could just easily double click and all the code would be done for me. But in android it appears to be a bit more obscure. I thought of using the touch event handlers but then if the user has a keyboard it won't detect the change since it's not touch. I figure android should have a native event for check box state change.

like image 910
Annerajb Avatar asked Jun 30 '10 12:06

Annerajb


People also ask

What is the way to get the checked status of checkbox in Android?

You can call isChecked() on a checkbox to get its status.

Do something when checkbox is checked 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.

How do I toggle checkbox in Android?

You can toggle the checkbox by doing this: checkbox. setChecked(! checkbox.

What is the use of checkbox in Android?

Checkboxes allow the user to select one or more options from a set. Typically, you should present each checkbox option in a vertical list. To create each checkbox option, create a CheckBox in your layout.


1 Answers

CheckBox repeatChkBx = ( CheckBox ) findViewById( R.id.repeat_checkbox ); repeatChkBx.setOnCheckedChangeListener(new OnCheckedChangeListener() {     @Override     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)     {         if ( isChecked )         {             // perform logic         }      } }); 
like image 104
Cristian Avatar answered Oct 05 '22 14:10

Cristian