Jack D
Jack D

Reputation: 129

How to check two checkbox unchecked in android

Hello i beginner in android. i am using four checkbox in my project. I want want to call one method after checkbox no 3 and 4 is unchecked state. how to write that code please help me.

Thanks in advance.

class myCheckBoxChnageClicker implements CompoundButton.OnCheckedChangeListener {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            // Is the view now checked?
            boolean checked = ((CheckBox) buttonView).isChecked();


            // Check which checkbox was clicked
            switch(buttonView.getId()) {

                case R.id.t3_check:

                    if (checked) {



                    } else {


                    }

                    break;

                case R.id.t4_check:

                    if (checked) {



                    } else {



                    }

                    break;

                case R.id.tsh_check:

                    if (checked) {



                    } else {


                    }

                    break;

                case R.id.weight_check:

                    if(checked) {



                    } else {



                    }

                    break;
                default:

            }







        }

        public void showTextNotification(String msgToDisplay) {


            if ((msgToDisplay.equals("Tsh_Check") && msgToDisplay.equals("Weight_Check"))) {

                Toast.makeText(getApplicationContext(), "match", Toast.LENGTH_SHORT).show();

            } else {


            }


        }
    }

Hello this is my code i want to call showTextNotification() method when 3 and 4 checkbox is unchecked state.

Upvotes: 2

Views: 228

Answers (3)

Gowthaman M
Gowthaman M

Reputation: 8272

Try this.

 final boolean Check_three = false;
 final boolean Check_foure  = false;

        class myCheckBoxChnageClicker implements CompoundButton.OnCheckedChangeListener {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                // Is the view now checked?
                boolean checked = ((CheckBox) buttonView).isChecked();


                // Check which checkbox was clicked
                switch(buttonView.getId()) {

                    case R.id.t3_check:

                        if (checked) {
                            Check_three = true;

                            if (Check_three == true && Check_foure == true)
                            {
                                showTextNotification("printmeaage");  
                            }


                        } else {
                            Check_three = false;

                        }

                        break;

                    case R.id.t4_check:

                        if (checked) {

                            Check_foure = true;
                            if (Check_three == true && Check_foure == true)
                            {
                                showTextNotification("printmeaage");
                            }

                        } else {

                            Check_foure = false;

                        }

                        break;

                    case R.id.tsh_check:

                        if (checked) {



                        } else {


                        }

                        break;

                    case R.id.weight_check:

                        if(checked) {



                        } else {



                        }

                        break;
                    default:

                }


            }

Upvotes: 1

Sanjay Kushwah
Sanjay Kushwah

Reputation: 189

checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            if (checkBox2.isChecked() && isChecked) {
                // Perform task
            }
        }
    });

    checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            if (checkBox1.isChecked() && isChecked) {
                // Perform task
            }
        }
    });

Upvotes: 1

veerdas
veerdas

Reputation: 11

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

Upvotes: 1

Related Questions